forked from Taritsyn/JavaScriptEngineSwitcher
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJsException.cs
More file actions
89 lines (78 loc) · 2.42 KB
/
JsException.cs
File metadata and controls
89 lines (78 loc) · 2.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
using System;
#if !NETSTANDARD1_3
using System.Runtime.Serialization;
using System.Security.Permissions;
#endif
namespace JavaScriptEngineSwitcher.ChakraCore.JsRt
{
/// <summary>
/// The exception returned from the Chakra engine
/// </summary>
#if !NETSTANDARD1_3
[Serializable]
#endif
public class JsException : Exception
{
/// <summary>
/// The error code
/// </summary>
private readonly JsErrorCode _errorCode;
/// <summary>
/// Gets a error code
/// </summary>
public JsErrorCode ErrorCode
{
get { return _errorCode; }
}
/// <summary>
/// Initializes a new instance of the <see cref="JsException"/> class
/// </summary>
/// <param name="errorCode">The error code returned</param>
public JsException(JsErrorCode errorCode)
: this(errorCode, "A fatal exception has occurred in a JavaScript runtime")
{ }
/// <summary>
/// Initializes a new instance of the <see cref="JsException"/> class
/// with a specified error message
/// </summary>
/// <param name="errorCode">The error code returned</param>
/// <param name="message">The error message</param>
public JsException(JsErrorCode errorCode, string message)
: base(message)
{
_errorCode = errorCode;
}
#if !NETSTANDARD1_3
/// <summary>
/// Initializes a new instance of the <see cref="JsException"/> class with serialized data
/// </summary>
/// <param name="info">The object that holds the serialized data</param>
/// <param name="context">The contextual information about the source or destination</param>
protected JsException(SerializationInfo info, StreamingContext context)
: base(info, context)
{
if (info != null)
{
_errorCode = (JsErrorCode)info.GetUInt32("ErrorCode");
}
}
#region Exception overrides
/// <summary>
/// Populates a <see cref="SerializationInfo"/> with the data needed to serialize the target object
/// </summary>
/// <param name="info">The <see cref="SerializationInfo"/> to populate with data</param>
/// <param name="context">The destination (see <see cref="StreamingContext"/>) for this serialization</param>
[SecurityPermission(SecurityAction.Demand, SerializationFormatter = true)]
public override void GetObjectData(SerializationInfo info, StreamingContext context)
{
if (info == null)
{
throw new ArgumentNullException(nameof(info));
}
base.GetObjectData(info, context);
info.AddValue("ErrorCode", (uint)_errorCode);
}
#endregion
#endif
}
}