UNPKG

@tsdotnet/exceptions

Version:

[![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg?style=flat-square)](https://github.com/tsdotnet/exceptions/blob/master/LICENSE) ![npm-publish](https://github.com/tsdotnet/exceptions/workflows/npm-publish/badge.svg) [![npm version](htt

55 lines 1.78 kB
/*! * @author electricessence / https://github.com/electricessence/ * Licensing: MIT * Based upon: https://msdn.microsoft.com/en-us/library/System.Exception%28v=vs.110%29.aspx */ const NAME = 'Exception'; /* * NOTE: * An 'Error' is an implementation that may vary per platform. * Using instanceof is only assured if not extending from Error. */ /** * Represents errors that occur during application execution. */ export default class Exception { /** * Initializes a new instance of the Exception class with a specified error message and optionally a reference to the inner exception that is the cause of this exception. * @param message * @param innerException */ constructor(message = '', innerException) { var _a; this.message = message; this.innerException = innerException; this.name = this.getName(); // Node has a .stack, let's use it... try { // To avoid unnecessary imports, use eval. // tslint:disable-next-line:no-eval const stack = ((_a = eval('new Error()') .stack) === null || _a === void 0 ? void 0 : _a.replace(/^Error\n/, '').replace(/(.|\n)+\s+at new.+/, '')) || ''; this.stack = this.toStringWithoutBrackets() + stack; } catch (ex) { this.stack = ''; } } /** * The string representation of the Exception instance. */ toString() { return `[${this.toStringWithoutBrackets()}]`; } /** * A string representation of the error type. */ getName() { return NAME; } toStringWithoutBrackets() { const m = this.message; return this.name + (m ? ': ' + m : ''); } } //# sourceMappingURL=Exception.js.map