Custom Errors
AbstractClassError
The AbstractClassError
is intended to be thrown whenever an abstract class is attempted instantiated directly.
import { AbstractClassError } from "@aedart/support/exceptions";
/**
* @abstract
*/
class MyAbstractClass {
constructor() {
if (new.target === MyAbstractClass) {
throw new AbstractClassError(MyAbstractClass);
}
}
}
const instance = new MyAbstractClass(); // AbstractClassError
LogicalError
To be thrown whenever there is an error in the programming logic.
Inspired by PHP's LogicException
import { LogicalError } from "@aedart/support/exceptions";
function print(person) {
if (printer === undefined) {
throw new LogicalError('Printer is missing, unable to print people');
}
}