ESC
No recent searches
Search by
Standard Library  /  Exception

Exception

Utilities for working with the Exception type.

Edit on GitHub

The Exception type represents an error that has occurred during computation.

Added in 0.3.0 No other changes yet.
from "exception" include Exception
exception ExampleError(Number)
exception ExampleError

Values

Functions and constants included in the Exception module.

Exception.registerPrinter

Added in 0.3.0 No other changes yet.
registerPrinter : (printer: (Exception => Option<String>)) => Void

Registers an exception printer. When an exception is thrown, all registered printers are called in order from the most recently registered printer to the least recently registered printer. The first Some value returned is used as the exception’s string value.

Parameters:

printer: The exception printer to register

Examples:

exception ExampleError(Number)

Exception.registerPrinter(e => {
  match (e) {
    ExampleError(lineNumber) =>
      Some("Error found on line: " ++ toString(lineNumber)),
    _ => None,
  }
})

throw ExampleError(1) // Error found on line: 1

Sign up for farm-to-inbox developer news

You can unsubscribe at any time. Read our privacy policy.

Copyright © 2024 The Grain Programming Language