Selaa lähdekoodia

share common base class for exceptions (#679)

Marko Lahma 5 vuotta sitten
vanhempi
commit
a8d19f315e

+ 1 - 1
Jint/Runtime/JavaScriptException.cs

@@ -7,7 +7,7 @@ using Jint.Pooling;
 
 namespace Jint.Runtime
 {
-    public class JavaScriptException : Exception
+    public class JavaScriptException : JintException
     {
         private string _callStack;
 

+ 28 - 0
Jint/Runtime/JintException.cs

@@ -0,0 +1,28 @@
+using System;
+using System.Runtime.Serialization;
+
+namespace Jint.Runtime
+{
+    /// <summary>
+    /// Base class for exceptions thrown by Jint.
+    /// </summary>
+    [Serializable]
+    public abstract class JintException : Exception
+    {
+        protected JintException()
+        {
+        }
+
+        protected JintException(SerializationInfo info, StreamingContext context) : base(info, context)
+        {
+        }
+
+        protected JintException(string message) : base(message)
+        {
+        }
+
+        protected JintException(string message, Exception innerException) : base(message, innerException)
+        {
+        }
+    }
+}

+ 2 - 4
Jint/Runtime/MemoryLimitExceededException.cs

@@ -1,8 +1,6 @@
-using System;
-
-namespace Jint.Runtime
+namespace Jint.Runtime
 {
-    public class MemoryLimitExceededException : Exception
+    public class MemoryLimitExceededException : JintException
     {
         public MemoryLimitExceededException() : base()
         {

+ 2 - 4
Jint/Runtime/RangeErrorException.cs

@@ -1,11 +1,9 @@
-using System;
-
-namespace Jint.Runtime
+namespace Jint.Runtime
 {
     /// <summary>
     /// Workaround for situation where engine is not easily accessible.
     /// </summary>
-    internal sealed class RangeErrorException : Exception
+    internal sealed class RangeErrorException : JintException
     {
         public RangeErrorException(string message) : base(message)
         {

+ 2 - 4
Jint/Runtime/RecursionDepthOverflowException.cs

@@ -1,10 +1,8 @@
-using System;
+using Jint.Runtime.CallStack;
 
 namespace Jint.Runtime
 {
-    using Jint.Runtime.CallStack;
-
-    public class RecursionDepthOverflowException : Exception
+    public class RecursionDepthOverflowException : JintException
     {
         public string CallChain { get; private set; }
 

+ 2 - 4
Jint/Runtime/StatementsCountOverflowException.cs

@@ -1,8 +1,6 @@
-using System;
-
-namespace Jint.Runtime
+namespace Jint.Runtime
 {
-    public class StatementsCountOverflowException : Exception 
+    public class StatementsCountOverflowException : JintException 
     {
         public StatementsCountOverflowException() : base("The maximum number of statements executed have been reached.")
         {

+ 2 - 4
Jint/Runtime/TypeErrorException.cs

@@ -1,11 +1,9 @@
-using System;
-
-namespace Jint.Runtime
+namespace Jint.Runtime
 {
     /// <summary>
     /// Workaround for situation where engine is not easily accessible.
     /// </summary>
-    internal sealed class TypeErrorException : Exception
+    internal sealed class TypeErrorException : JintException
     {
         public TypeErrorException(string message) : base(message)
         {