JsException Class
A JavaScript exception: the .NET exception that carries a thrown JavaScript value.
public sealed class JsException : ExceptionRemarks
The constructors that take a message (or nothing) throw a JavaScript Error whose message is the message of the exception: the error is created in the current realm the first time JsException.Value is read (e.g. when a script catches it). Use JsRealm.CreateException to throw another type of error.
- Inheritance
ExceptionJsException
Constructors
| Name | Description |
|---|---|
| JsException() | Initializes a new instance of the JsException class: it throws an Error without message. |
| JsException(JsValue) | Initializes a new instance of the JsException class with the thrown value. |
| JsException(JsValue, JsSourceLocation?) | Initializes a new instance of the JsException class with the thrown value and the position of the code that threw it (e.g. the position of a syntax error). |
| JsException(string) | Initializes a new instance of the JsException class with a message: it throws an Error with this message. |
| JsException(string, Exception) | Initializes a new instance of the JsException class with a message and an inner exception: it throws an Error with this message. |
JsException overloads
JsException()
JsException.csInitializes a new instance of the JsException class: it throws an Error without message.
public JsException()JsException(JsValue)
JsException.csInitializes a new instance of the JsException class with the thrown value.
public JsException(JsValue value)Parameters
valueJsValue
JsException(JsValue, JsSourceLocation?)
JsException.csInitializes a new instance of the JsException class with the thrown value and the position of the code that threw it (e.g. the position of a syntax error).
public JsException(JsValue value, JsSourceLocation? location)Parameters
valueJsValuelocationJsSourceLocation?
JsException(string)
JsException.csInitializes a new instance of the JsException class with a message: it throws an Error with this message.
public JsException(string message)Parameters
messagestring
JsException(string, Exception)
JsException.csInitializes a new instance of the JsException class with a message and an inner exception: it throws an Error with this message.
Properties
| Name | Description |
|---|---|
| JavaScriptStackTrace | Gets the JavaScript frames of the stack trace of the thrown error, one per line ( at f (file.js:1:2)), the innermost first: the stack of the error without its first line (see JsObject.GetErrorStack). The frames are the ones of the code that created the error, which can differ from the code that threw it. It is null when the thrown value is not an error object with a stack trace (e.g. throw 42), and empty when the error was created without JavaScript code on the stack. |
| Location | Gets the position of the code that threw the exception, when it was thrown by JavaScript code. |
| Value | Gets the thrown value. For an exception created with a message, it is an Error of the current realm, created on first access (undefined when no engine is entered on the thread at that time). |
JavaScriptStackTrace
JsException.csGets the JavaScript frames of the stack trace of the thrown error, one per line ( at f (file.js:1:2)), the innermost first: the stack of the error without its first line (see JsObject.GetErrorStack). The frames are the ones of the code that created the error, which can differ from the code that threw it. It is null when the thrown value is not an error object with a stack trace (e.g. throw 42), and empty when the error was created without JavaScript code on the stack.
public string? JavaScriptStackTrace { get; }Property value
Location
JsException.csGets the position of the code that threw the exception, when it was thrown by JavaScript code.
public JsSourceLocation? Location { get; }Property value
Value
JsException.csMethods
| Name | Description |
|---|---|
| ToString() | Returns the description of the exception, followed by its JavaScript stack trace when it has one. |