UNPKG

@itwin/core-bentley

Version:

Bentley JavaScript core components

43 lines 2.25 kB
/** @packageDocumentation * @module Errors */ /** A function to be notified when an unexpected error happens * @public */ export type OnUnexpectedError = (error: any) => void; /** * Utility for handling/reporting unexpected runtime errors. This class establishes a global handler for * unexpected errors, and programmers should use its `handle` method when they occur. Generally, unexpected * errors should not cause program termination, and should instead be logged and swallowed. However, for * development/debugging, it can be helpful to re-throw exceptions so they are not missed. * @public */ export declare class UnexpectedErrors { /** handler for re-throwing exceptions directly */ static readonly reThrowImmediate: (e: any) => never; /** handler for re-throwing exceptions from an asynchronous interval (so the current call stack is not aborted) */ static readonly reThrowDeferred: (e: any) => NodeJS.Timeout; /** handler for logging exception to console */ static readonly consoleLog: (e: any) => void; /** handler for logging exception with [[Logger]] */ static readonly errorLog: (e: any) => void; private static _telemetry; private static _handler; private constructor(); /** Add a "telemetry tracker" for unexpected errors. Useful for tracking/reporting errors without changing handler. * @returns a method to remove the tracker */ static addTelemetry(tracker: OnUnexpectedError): () => void; /** call this method when an unexpected error happens so the global handler can process it. * @param error the unexpected error * @param notifyTelemetry if false, don't notify telemetry trackers. Use this for exceptions from third-party code, for example. */ static handle(error: any, notifyTelemetry?: boolean): void; /** establish a new global *unexpected error* handler. * @param handler the new global handler. You may provide your own function or use one of the static members of this class. * The default is [[errorLog]]. * @returns the previous handler. Useful to temporarily change the handler. */ static setHandler(handler: OnUnexpectedError): OnUnexpectedError; } //# sourceMappingURL=UnexpectedErrors.d.ts.map