Skip to Content
API reference

Error

A JavaScript error object or any JVM Throwable. new Error(message) constructs the shared runtime error class.

ValuesType: typescriptnative.ErrorArtifact: com.margelo:typescript-native-stdlib

Type mapping

TypeScriptJVMNotes
new Error(message)typescriptnative.ErrorConstructed by TypeScript, thrown to Java as a RuntimeException.
Errorjava.lang.ThrowableEvery Throwable is an Error in TypeScript.

Error class

public class Error extends RuntimeException

An error that JavaScript created: new Error(message) in TypeScript or in a compiled npm module. It owns the state of its own property message. TypeScript, the compiled JavaScript of every project that uses this class and Java read and write this one state, so a change made through any of them is seen by all, for as long as the error lives. Every other Throwable is a JVM exception, whose message TypeScript and JavaScript can only read.

Constructors

Error()

new Error(): no own message.

Error(String message)

Creates an error with a string message. A null string gives no own message.

message
the message, or null for absence

Methods

String getMessage()

error.message as a string, for TypeScript, Java and Kotlin. A stored string is one field read on any thread. A message that a getter computes runs the getter once, in the realm of the object that has it, and returns its result. A value that is not a string throws a TypeError; nothing is converted. So this method can throw what the getter throws and the TypeError. It never returns null, and a subclass cannot override it.

Returns
the string message
Throws TypeError
when the message is not a string
void setMessage(String value)

Strict typed assignment. A null string is stored as an empty string.

value
the string to assign
Throws TypeError
when the property refuses the write
defaultNameprotected
String defaultName()

The name the source constructor gives its errors.

Returns
the default name
String jsName()

The typed name: the source object's name, or the default name for a typed construction.

Returns
the name
String jsText()

The source Error conversion. Java toString keeps its separate logging rule.

Returns
the converted source text
String jsStack()

The stack as typed code reads it.

Returns
the stack text
String toString()

The class name, then : and the message when it is not empty. A stored string and a getter are read as getMessage() reads them, so a getter runs and what it throws propagates. A data value that is not a string prints the class name only, as Error.prototype.toString prints only the name for an undefined message; no TypeError.

Error.TypeError class

public static class TypeError extends Error

JavaScript's TypeError.

Constructors

TypeError(String message)

Creates a TypeError with a string message.

message
the message

Methods

defaultNameprotected
String defaultName()

Generated when the website builds, from Error.java.

Language

Remembered on every API page

On this page