JsException Class

A JavaScript exception: the .NET exception that carries a thrown JavaScript value.

public sealed class JsException : Exception

Remarks

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
Exception JsException

Constructors

NameDescription
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.cs

Initializes a new instance of the JsException class: it throws an Error without message.

public JsException()

JsException(JsValue)

JsException.cs

Initializes a new instance of the JsException class with the thrown value.

public JsException(JsValue value)
Parameters
value JsValue

JsException(JsValue, JsSourceLocation?)

JsException.cs

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).

public JsException(JsValue value, JsSourceLocation? location)
Parameters
value JsValue
location JsSourceLocation?

JsException(string)

JsException.cs

Initializes a new instance of the JsException class with a message: it throws an Error with this message.

public JsException(string message)
Parameters
message string

JsException(string, Exception)

JsException.cs

Initializes a new instance of the JsException class with a message and an inner exception: it throws an Error with this message.

public JsException(string message, Exception innerException)
Parameters
message string
innerException Exception

Properties

NameDescription
JavaScriptStackTraceGets 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.
LocationGets the position of the code that threw the exception, when it was thrown by JavaScript code.
ValueGets 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.cs

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.

public string? JavaScriptStackTrace { get; }

Property value

string?

Gets the position of the code that threw the exception, when it was thrown by JavaScript code.

public JsSourceLocation? Location { get; }

Property value

JsSourceLocation?

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).

public JsValue Value { get; }

Property value

JsValue

Methods

NameDescription
ToString()Returns the description of the exception, followed by its JavaScript stack trace when it has one.

ToString()

JsException.cs

Returns the description of the exception, followed by its JavaScript stack trace when it has one.

public override string ToString()

Returns

string