interface BaseExceptionConstructor { readonly names: Record; /** * Creates an Exception. * For internal use only! * Please use the factory methods, to create an Exception! * * @param name The type name, the default is `UNKNOWN`. * @param message The associated message. * @param cause The cause of this exception. */ new (name: string, message?: string, cause?: Error | Exception): ExceptionType; } /** * Converts names like `"ILLEGAL_STATE_ERROR"` to methods `illegalStateError` at given constructor. * * Note: This should only be used by custom Exception classes. It is exported as extra name! * * @example * ```ts * import {default as Exception, registerTypes} from "apprt-core/Exception"; * * // register new exception type * registerTypes(Exception, "ILLEGAL_STATE_ERROR"); * // now clients can invoke * const e = Exception.illegalStateError("error message"); * e.name === 'ILLEGAL_STATE_ERROR'; * e.message === "error message"; * ``` * @param exceptionConstructor the exception constructor. * @param names the exception names to register. */ declare function registerTypes(exceptionConstructor: BaseExceptionConstructor, ...names: Name[]): void; declare enum ExceptionNames { "UNKNOWN" = "UNKNOWN", "ILLEGAL_STATE_ERROR" = "ILLEGAL_STATE_ERROR", "ILLEGAL_ARGUMENT_ERROR" = "ILLEGAL_ARGUMENT_ERROR", "NOT_IMPLEMENTED" = "NOT_IMPLEMENTED" } interface Exception extends Error { /** * Type name of this exception. */ readonly name: string; /** * Type cause of this exception, maybe undefined. */ readonly cause: Error | Exception | undefined; /** * Current stack trace. */ readonly stack: string; /** Returns the exceptions stack trace. */ toString(): string; } /** * An Exception is a special error class to allow trees of causes. * @example * ```ts * import Exception from "apprt-core/Exception"; * * try { * // code with throws an error * } catch(e) { * // wrap into exception class to get stacktraces * throw Exception.wrap(e); * } * ``` */ declare const Exception: ExceptionConstructor; /** Interface of the exception constructor. */ interface ExceptionConstructor extends BaseExceptionConstructor { /** * Wraps errors into Exceptions to get correct stacktraces. * * @param error the error * @param msg the error message * @example * ```ts * import Exception from "apprt-core/Exception"; * * try { * // code with throws an error * } catch(e) { * // wrap into exception class to get stacktraces * throw Exception.wrap(e); * } * ``` */ wrap(error: Error | Exception, msg?: string): Exception; /** * Wraps errors into Exceptions to get correct stacktraces. * * @param error the error message */ wrap(error: string): Exception; } interface ExceptionConstructor { /** * Factory method for Exceptions of type 'UNKNOWN' */ unknown(message: string, cause?: Error | Exception): Exception; /** * Factory method for Exceptions of type 'ILLEGAL_STATE_ERROR' */ illegalStateError(message: string, cause?: Error | Exception): Exception; /** * Factory method for Exceptions of type 'ILLEGAL_ARGUMENT_ERROR' */ illegalArgumentError(message: string, cause?: Error | Exception): Exception; /** * Factory method for Exceptions of type 'NOT_IMPLEMENTED' */ notImplemented(message: string, cause?: Error | Exception): Exception; } export { Exception, ExceptionNames, Exception as default, registerTypes }; export type { BaseExceptionConstructor, ExceptionConstructor };