Error Utilities API reference for error handling utility functions alert-triangle Guide

Error Utilities

The Error utilities provide functions for enhanced error handling and throwing in JavaScript.

Functions

fatal

function fatal(message, { errorType = Error, metadata = {}, onError = null, removeStackLines = 1 } = {})

Throws an error with enhanced control over the error type, metadata, and stack trace.

Asynchronous Error Throwing This function uses queueMicrotask to throw the error asynchronously, allowing the current execution context to complete.

Parameters

NameTypeDescription
messagestringThe error message
optionsobjectOptional configuration
Options
NameTypeDefaultDescription
errorTypefunctionErrorThe type of error to throw
metadataobjectAdditional data to attach to the error
onErrorfunctionnullCallback to execute before throwing the error
removeStackLinesnumber1Number of stack trace lines to remove

Example

import { fatal } from '@semantic-ui/utils';
try {
fatal("Something went wrong", {
errorType: TypeError,
metadata: { code: "ERR_001" },
onError: (err) => console.log("Error occurred:", err.message)
});
} catch (error) {
console.error(error);
}