[dojo-contributors] Stance on custom error types
mark at novemberborn.net
Mon Jun 4 08:41:26 EDT 2012
Dojo seems to do custom errors by adding a `dojoType` property to the error instance. Examples in `dojo/request` and `dojo/io`. The new Promise code however uses a subclassed Error.
Error.captureStackTrace && Error.captureStackTrace(this, CancelError);
this.message = message || "The deferred was cancelled.";
this.name = "CancelError";
CancelError.prototype = new Error;
CancelError.prototype.constructor = CancelError;
I prefer subclassed errors because they're easier to instantiate and test for (either using `instanceof` or checking their `name`). We could even add `dojoType` properties.
What is your preference?
In any case, we need to standardize these across the codebase.
More information about the dojo-contributors