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
Js Module
Overview
Js
submodules
  • Array
  • Array2
  • BigInt
  • Blob
  • Console
  • Date
  • Dict
  • Exn
    • t
      t
    • v
      asJsExn
    • v
      stack
    • v
      message
    • v
      name
    • v
      fileName
    • v
      isCamlExceptionOrOpenVariant
    • v
      anyToExnInternal
    • v
      raiseError
    • v
      raiseEvalError
    • v
      raiseRangeError
    • v
      raiseReferenceError
    • v
      raiseSyntaxError
    • v
      raiseTypeError
    • v
      raiseUriError
  • File
  • Float
  • Global
  • Int
  • Json
    • Kind
  • List
  • Map
  • Math
  • Null
  • Null_undefined
  • Nullable
  • Obj
  • Option
  • Promise
  • Promise2
  • Re
  • Result
  • Set
  • String
  • String2
  • TypedArray2
    • DataView
    • Float64Array
    • Float32Array
    • Uint32Array
    • Int32Array
    • Uint16Array
    • Int16Array
    • Uint8ClampedArray
    • Uint8Array
    • Int8Array
    • ArrayBuffer
    Typed_array
    • DataView
    • Float64_array
    • Float64Array
    • Float32_array
    • Float32Array
    • Uint32Array
    • Int32_array
    • Int32Array
    • Uint16Array
    • Int16Array
    • Uint8ClampedArray
    • Uint8Array
    • Int8Array
    • S
    • ArrayBuffer
    • Type
  • Types
  • Undefined
  • Vector
  • WeakMap
  • WeakSet
  • API / Js / Exn

    Exn

    Provide utilities for dealing with JS exceptions.

    t

    RESCRIPT
    type t

    Represents a JS exception

    asJsExn

    RESCRIPT
    let asJsExn: exn => option<t>

    stack

    RESCRIPT
    let stack: t => option<string>

    message

    RESCRIPT
    let message: t => option<string>

    name

    RESCRIPT
    let name: t => option<string>

    fileName

    RESCRIPT
    let fileName: t => option<string>

    isCamlExceptionOrOpenVariant

    RESCRIPT
    let isCamlExceptionOrOpenVariant: 'a => bool

    internal use only

    anyToExnInternal

    RESCRIPT
    let anyToExnInternal: 'a => exn

    anyToExnInternal(obj) will take any value obj and wrap it in a Js.Exn.Error if given value is not an exn already. If obj is an exn, it will return obj without any changes.

    This function is mostly useful for cases where you want to unify a type of a value that potentially is either exn, a JS error, or any other JS value really (e.g. for a value passed to a Promise.catch callback)

    IMPORTANT: This is an internal API and may be changed / removed any time in the future.

    Examples

    RESCRIPT
    switch (Js.Exn.unsafeAnyToExn("test")) { | Js.Exn.Error(v) => switch(Js.Exn.message(v)) { | Some(str) => Js.log("We won't end up here") | None => Js.log2("We will land here: ", v) } }

    raiseError

    RESCRIPT
    let raiseError: string => 'a

    Raise Js exception Error object with stacktrace

    raiseEvalError

    RESCRIPT
    let raiseEvalError: string => 'a

    raiseRangeError

    RESCRIPT
    let raiseRangeError: string => 'a

    raiseReferenceError

    RESCRIPT
    let raiseReferenceError: string => 'a

    raiseSyntaxError

    RESCRIPT
    let raiseSyntaxError: string => 'a

    raiseTypeError

    RESCRIPT
    let raiseTypeError: string => 'a

    raiseUriError

    RESCRIPT
    let raiseUriError: string => 'a
    Types and values
    • t
      t
    • v
      asJsExn
    • v
      stack
    • v
      message
    • v
      name
    • v
      fileName
    • v
      isCamlExceptionOrOpenVariant
    • v
      anyToExnInternal
    • v
      raiseError
    • v
      raiseEvalError
    • v
      raiseRangeError
    • v
      raiseReferenceError
    • v
      raiseSyntaxError
    • v
      raiseTypeError
    • v
      raiseUriError

    © 2024 The ReScript Project

    Software and assets distribution powered by KeyCDN.

    About
    • Community
    • ReScript Association
    Find us on