/* Require the dependency */varCustomError=require("error.js");/* Create your custom error once */varMyCustomError=CustomError.create("MyCustomError");/* Throw your custom error */thrownewMyCustomError("oops");
Create a custom error with additional properties :
varNotFoundError=CustomError.create({name : "NotFound",message : "Content not found",statusCode : 404});
Throw a custom error :
thrownewMyCustomError("oops");
Throw a custom error with additional properties :
thrownewNotFoundError({message : "Could not find requested user",userId : "123-456-789"});
Check if an Error is a custom error :
varMyCustomError=CustomError.create("MyCustomError");varmyCustomError=newMyCustomError("oops");/* Will return true */CustomError.isCustom(myCustomError);
vare=newError("oops");/* Will return false */CustomError.isCustom(e);