@rightcapital/exceptions
Version:
TypeScript Exception definitions inspired by PHP SPL Exceptions etc...
32 lines • 1.4 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.BaseException = void 0;
/**
* The Base Exception that be used to emulate the PHP Base Exception
* All exception should be based on this Error type
* @public
*
* @see https://www.php.net/manual/en/spl.exceptions.php
* @see https://javascript.info/custom-errors
*/
class BaseException extends Error {
/**
* @param message A human-readable description of the error.
* @param cause The value of cause can be of any type. You should not make assumptions that the error you caught has an Error as its cause, in the same way that you cannot be sure the variable bound in the catch statement is an Error either. The "Providing structured data as the error cause" example below shows a case where a non-error is deliberately provided as the cause.
*/
constructor(message, cause) {
super(message);
this.cause = cause;
}
/**
* If the Error is caused by the cause we passed in the construction method
*
* @param cause the cause we assume that cause the current exception
* @returns true if the cause we passed is the original cause when the Exception constructed. otherwise, it returns false
*/
isCausedBy(cause) {
return cause === this.cause;
}
}
exports.BaseException = BaseException;
//# sourceMappingURL=base.exception.js.map