Skip to main content


Error values and inspection.

The Error type is the argument to throw, parameter of catch. The Error type is opaque.

Type Error

type Error = Prim.Types.Error

Error value resulting from async computations

Type ErrorCode

type ErrorCode = Prim.ErrorCode

Error code to classify different kinds of user and system errors:

type ErrorCode = {
// Fatal error.
// Transient error.
// Destination invalid.
// Explicit reject by canister code.
// Canister trapped.
// Future error code (with unrecognized numeric code).
#future : Nat32;
// Error issuing inter-canister call
// (indicating destination queue full or freezing threshold crossed).
#call_error : { err_code : Nat32 }

Value reject

let reject : (message : Text) -> Error

Create an error from the message with the code #canister_reject.


import Error "mo:base/Error";

Error.reject("Example error") // can be used as throw argument

Value code

let code : (error : Error) -> ErrorCode

Returns the code of an error.


import Error "mo:base/Error";

let error = Error.reject("Example error");
Error.code(error) // #canister_reject

Value message

let message : (error : Error) -> Text

Returns the message of an error.


import Error "mo:base/Error";
import Debug "mo:base/Debug";

let error = Error.reject("Example error");
Error.message(error) // "Example error"