In Java I would declare a function like this:
public boolean Test(boolean test) throws Exception {
if (test == true)
return false;
throw new Excepti
You could treat JavaScript's Error as Java's RuntimeException (unchecked exception).
You can extend JavaScript's Error but you have to use Object.setPrototypeOf to restore the prototype chain because Error breaks it. The need for setPrototypeOf is explained in this answer too.
export class AppError extends Error {
code: string;
constructor(message?: string, code?: string) {
super(message); // 'Error' breaks prototype chain here
Object.setPrototypeOf(this, new.target.prototype); // restore prototype chain
this.name = 'AppError';
this.code = code;
}
}