BadScript 2
Loading...
Searching...
No Matches
BadRuntimeError.cs
Go to the documentation of this file.
3
8
13{
15 "Error",
16 (_, _) => throw new BadRuntimeException("Error")
17 );
18
25 public BadRuntimeError(BadRuntimeError? innerError, BadObject obj, string stackTrace)
26 {
27 InnerError = innerError;
28 ErrorObject = obj;
29 StackTrace = stackTrace;
30 }
31
35 public string StackTrace { get; }
36
40 public BadRuntimeError? InnerError { get; set; }
41
45 public BadObject ErrorObject { get; }
46
53 public static BadRuntimeError FromException(Exception e, string? scriptStackTrace = null)
54 {
55 BadRuntimeError? inner = e.InnerException == null ? null : FromException(e.InnerException);
56
57 string st;
58
59 if (scriptStackTrace == null)
60 {
61 st = e.StackTrace;
62 }
63 else
64 {
65 st = "Script Stack Trace: " +
66 Environment.NewLine +
67 scriptStackTrace +
68 Environment.NewLine +
69 "Runtime Stacktrace:" +
70 Environment.NewLine +
71 e.StackTrace;
72 }
73
74 return new BadRuntimeError(inner, e.Message, st);
75 }
76
79 {
80 return Prototype;
81 }
82
84 public override string ToSafeString(List<BadObject> done)
85 {
86 done.Add(this);
87
88 return $"{ErrorObject.ToSafeString(done)} at\n{StackTrace}\n{InnerError?.ToSafeString(done) ?? ""}";
89 }
90
92 public override BadObjectReference GetProperty(string propName, BadScope? caller = null)
93 {
94 switch (propName)
95 {
96 case "StackTrace":
97 return BadObjectReference.Make("Error.StackTrace", () => StackTrace);
98 case "InnerError":
99 return BadObjectReference.Make("Error.InnerError", () => InnerError ?? Null);
100 case "ErrorObject":
101 return BadObjectReference.Make("Error.ErrorObject", () => ErrorObject);
102 }
103
104 return base.GetProperty(propName, caller);
105 }
106
108 public override bool HasProperty(string propName, BadScope? caller = null)
109 {
110 return propName is "StackTrace" or "InnerError" or "ErrorObject" ||
111 base.HasProperty(propName, caller);
112 }
113}
Implements the Scope for the Script Engine.
Definition BadScope.cs:238
Implements the Error Object Type.
override bool HasProperty(string propName, BadScope? caller=null)
Returns true if the object contains a given property or there exists an extension for the current Ins...
override BadClassPrototype GetPrototype()
BadRuntimeError(BadRuntimeError? innerError, BadObject obj, string stackTrace)
Creates a new Error Object.
static readonly BadClassPrototype Prototype
override BadObjectReference GetProperty(string propName, BadScope? caller=null)
Returns a Reference to the Property with the given Name.The Property Reference
string StackTrace
The Stacktrace of the Error.
BadObject ErrorObject
The Object that was thrown.
BadRuntimeError? InnerError
The Inner Error.
override string ToSafeString(List< BadObject > done)
static BadRuntimeError FromException(Exception e, string? scriptStackTrace=null)
Creates a BadRuntimeError from an Exception.
The Base Class for all BadScript Objects.
Definition BadObject.cs:14
virtual BadObjectReference GetProperty(string propName, BadScope? caller=null)
Returns a Reference to the Property with the given Name.
Definition BadObject.cs:129
static readonly BadObject Null
The Null Value for the BadScript Language.
Definition BadObject.cs:28
Implements the base functionality for a BadScript Reference.
static BadObjectReference Make(string refText, Func< BadObject > getter, Action< BadObject, BadPropertyInfo?>? setter=null, Action? delete=null)
Creates a new Reference Object.
Implements a Class Prototype for the BadScript Language.
Contains the Error Objects for the BadScript2 Language.
Contains the Runtime Objects.
Definition BadArray.cs:10