forked from ClearFoundry/ClearScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathScriptEngineException.cs
More file actions
158 lines (134 loc) · 5.85 KB
/
ScriptEngineException.cs
File metadata and controls
158 lines (134 loc) · 5.85 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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
using System;
using System.Runtime.Serialization;
using Microsoft.ClearScript.Util;
namespace Microsoft.ClearScript
{
/// <summary>
/// The exception that is thrown when an error occurs during script execution or script object access.
/// </summary>
[Serializable]
public class ScriptEngineException : InvalidOperationException, IScriptEngineException
{
private readonly string engineName;
private const string engineNameItemName = "ScriptEngineName";
private readonly string errorDetails;
private const string errorDetailsItemName = "ScriptErrorDetails";
private readonly bool isFatal;
private const string isFatalItemName = "IsFatal";
private readonly bool executionStarted;
private const string executionStartedItemName = "ExecutionStarted";
private const string defaultMessage = "An error occurred during script execution";
#region constructors
/// <summary>
/// Initializes a new <see cref="ScriptEngineException"/> instance.
/// </summary>
public ScriptEngineException()
: base(defaultMessage)
{
// ReSharper disable once RedundantBaseQualifier
errorDetails = base.Message;
}
/// <summary>
/// Initializes a new <see cref="ScriptEngineException"/> with the specified error message.
/// </summary>
/// <param name="message">The error message.</param>
public ScriptEngineException(string message)
: base(MiscHelpers.EnsureNonBlank(message, defaultMessage))
{
// ReSharper disable once RedundantBaseQualifier
errorDetails = base.Message;
}
/// <summary>
/// Initializes a new <see cref="ScriptEngineException"/> with the specified error message and nested exception.
/// </summary>
/// <param name="message">The error message.</param>
/// <param name="innerException">The exception that caused the current exception to be thrown.</param>
public ScriptEngineException(string message, Exception innerException)
: base(MiscHelpers.EnsureNonBlank(message, defaultMessage), innerException)
{
// ReSharper disable once RedundantBaseQualifier
errorDetails = base.Message;
}
/// <summary>
/// Initializes a new <see cref="ScriptEngineException"/> 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 ScriptEngineException(SerializationInfo info, StreamingContext context)
: base(info, context)
{
engineName = info.GetString(engineNameItemName);
errorDetails = info.GetString(errorDetailsItemName);
isFatal = info.GetBoolean(isFatalItemName);
executionStarted = info.GetBoolean(executionStartedItemName);
}
internal ScriptEngineException(string engineName, string message, string errorDetails, int errorCode, bool isFatal, bool executionStarted, Exception innerException)
: base(MiscHelpers.EnsureNonBlank(message, defaultMessage), innerException)
{
this.engineName = engineName;
// ReSharper disable once RedundantBaseQualifier
this.errorDetails = MiscHelpers.EnsureNonBlank(errorDetails, base.Message);
this.isFatal = isFatal;
this.executionStarted = executionStarted;
if (errorCode != 0)
{
HResult = errorCode;
}
}
#endregion
#region IScriptEngineException implementation
/// <summary>
/// Gets an <see href="http://en.wikipedia.org/wiki/HRESULT">HRESULT</see> error code if one is available, zero otherwise.
/// </summary>
int IScriptEngineException.HResult
{
get { return HResult; }
}
/// <summary>
/// Gets the name associated with the script engine instance.
/// </summary>
public string EngineName
{
get { return engineName; }
}
/// <summary>
/// Gets a detailed error message if one is available, <c>null</c> otherwise.
/// </summary>
public string ErrorDetails
{
get { return errorDetails; }
}
/// <summary>
/// Gets a value that indicates whether the exception represents a fatal error.
/// </summary>
public bool IsFatal
{
get { return isFatal; }
}
/// <summary>
/// Gets a value that indicates whether script code execution had started before the current exception was thrown.
/// </summary>
public bool ExecutionStarted
{
get { return executionStarted; }
}
#endregion
#region InvalidOperationException 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>
public override void GetObjectData(SerializationInfo info, StreamingContext context)
{
base.GetObjectData(info, context);
info.AddValue(engineNameItemName, engineName);
info.AddValue(errorDetailsItemName, errorDetails);
info.AddValue(isFatalItemName, isFatal);
info.AddValue(executionStartedItemName, executionStarted);
}
#endregion
}
}