packageDocumentation module import { Logger } from "./Logger" ; public export type OnUnexpectedError = ( error : any ) => void ; public export class UnexpectedErrors { /** handler for re-throwing exceptions directly */ public static readonly reThrowImmediate = ( e ) => { throw e ; } ; /** handler for re-throwing exceptions from an asynchronous interval (so the current call stack is not aborted) */ public static readonly reThrowDeferred = ( e ) => setTimeout ( ( ) => { throw e ; } , 0 ) ; /** handler for logging exception to console */ public static readonly consoleLog = ( e ) => console . error ( e ) ; /** handler for logging exception with [[Logger]] */ public static readonly errorLog = ( e ) => Logger . logException ( "unhandled" , e ) ; private static _telemetry : OnUnexpectedError [ ] = [ ] ; private static _handler = this . errorLog ; private constructor ( ) { } returns public static addTelemetry ( tracker ) { this . _telemetry . push ( tracker ) ; return ( ) => this . _telemetry . splice ( this . _telemetry . indexOf ( tracker ) , 1 ) ; } param error param notifyTelemetry public static handle ( error , notifyTelemetry = true ) { this . _handler ( error ) ; if ( notifyTelemetry ) this . _telemetry . forEach ( ( telemetry ) => { try { telemetry ( error ) ; } catch ( _ ) { } } ) ; } param handler returns public static setHandler ( handler ) { const oldHandler = this . _handler ; this . _handler = handler ; return oldHandler ; } }