This is the latest docs version
Quick Links
  • -Overview
  • -Language Features
  • -JS Interop
  • -Build System
Documentation
Language Manual
Reference for all language features
ReScript & React
First class bindings for ReactJS
GenType
Seamless TypeScript integration
Reanalyze
Dead Code & Termination analysis
Exploration
Packages
Explore third party libraries and bindings
Syntax Lookup
Discover all syntax constructs
APIPlaygroundBlogCommunity
  • Playground
  • Blog
  • Twitter
  • GitHub
  • Forum
Core Module
Overview
Core
submodules
  • Array
  • ArrayBuffer
  • AsyncIterator
  • BigInt
  • BigInt64Array
    • Constants
    BigUint64Array
    • Constants
  • Console
  • DataView
  • Date
    • UTC
  • Dict
  • Error
    • t
      t
    • v
      fromException
    • v
      toException
    • v
      stack
    • v
      message
    • v
      name
    • v
      fileName
    • v
      make
    • v
      raise
    • v
      panic
    • URIError
    • TypeError
    • SyntaxError
    • ReferenceError
    • RangeError
    • EvalError
  • Exn
  • Float
    • Constants
    Float32Array
    • Constants
    Float64Array
    • Constants
    Int
    • Constants
    Int16Array
    • Constants
    Int32Array
    • Constants
    Int8Array
    • Constants
  • Internal
  • Intl
    • Segments
    • Segmenter
    • RelativeTimeFormat
    • PluralRules
    • NumberFormat
      • Grouping
    • Locale
    • ListFormat
    • DateTimeFormat
    • Collator
    • Common
  • Iterator
  • JSON
    • Decode
    • Encode
    • Classify
  • List
  • Map
  • MapperRt
  • Math
    • Int
    • Constants
  • Null
  • Nullable
  • Object
  • Option
  • Ordering
  • Promise
  • Re
    • Result
    RegExp
    • Result
  • Result
  • Set
  • String
  • Symbol
  • Type
    • Classify
  • TypedArray
  • Uint16Array
    • Constants
    Uint32Array
    • Constants
    Uint8Array
    • Constants
    Uint8ClampedArray
    • Constants
  • WeakMap
  • WeakSet
  • API / Core / Error

    Error

    Functions for working with JavaScript exceptions.

    See Error on MDN.

    t

    RESCRIPT
    type t = Js.Exn.t

    Represents a JavaScript exception.

    fromException

    RESCRIPT
    let fromException: exn => option<t>

    toException

    RESCRIPT
    let toException: t => exn

    Turns an Error.t into an exn.

    Examples

    RESCRIPT
    let error = Error.make("Something went wrong.") let asExn = error->Error.toException // `asExn` is now type `exn`

    stack

    RESCRIPT
    let stack: t => option<string>

    stack(error) retrieves the stack property of the error, if it exists. The stack is a list of what functions were called, and what files they are defined in, prior to the error happening.

    See Error.prototype.stack on MDN.

    Example

    RESCRIPT
    let error = Error.make("error") Console.log(error->Error.stack) // Logs `stack` if it exists on `someError`

    message

    RESCRIPT
    let message: t => option<string>

    message(error) retrieves the message property of the error, if it exists.

    See Error.prototype.message on MDN.

    Example

    RESCRIPT
    let error = Error.SyntaxError.make("Some message here") Console.log(error->Error.message) // Logs "Some message here" to the console

    name

    RESCRIPT
    let name: t => option<string>

    name(error) retrieves the name property of the error, if it exists.

    See Error.prototype.name on MDN.

    Example

    RESCRIPT
    let error = Error.SyntaxError.make("Some message here") Console.log(error->Error.name) // Logs "SyntaxError" to the console

    fileName

    RESCRIPT
    let fileName: t => option<string>

    fileName(error) retrieves the fileName property of the error, if it exists.

    See Error.prototype.fileName on MDN.

    make

    RESCRIPT
    let make: string => t

    make(message) creates a new error, setting its message to the provided value.

    See Error on MDN.

    Example

    RESCRIPT
    let error = Error.make("Some message here") Console.log(error->Error.message) // Logs "Some message here" to the console Console.log(error->Error.name) // Logs "Error" to the console, because this is a regular error

    raise

    RESCRIPT
    let raise: t => 'a

    Raises (throws in JavaScript language) the provided Error.t, which will stop execution.

    Examples

    RESCRIPT
    let error = Error.make("Everything is upside down.") if 5 > 10 { error->Error.raise } else { Console.log("Phew, sanity still rules.") }

    panic

    RESCRIPT
    let panic: string => 'a

    Raises a panic exception with the given message.

    A panic exception is a native JavaScript exception that is not intended to be caught and handled. Compared to a ReScript exception this will give a better stack trace and debugging experience.

    Examples

    RESCRIPT
    Error.panic("Uh oh. This was unexpected!")
    Types and values
    • t
      t
    • v
      fromException
    • v
      toException
    • v
      stack
    • v
      message
    • v
      name
    • v
      fileName
    • v
      make
    • v
      raise
    • v
      panic

    © 2024 The ReScript Project

    Software and assets distribution powered by KeyCDN.

    About
    • Community
    • ReScript Association
    Find us on