Wither
A feature-full decorator library for node.js
handle(func, [type], handler)
type is optional and can be:
- Name of a precondition
- Error Type
Wrap functions with error handling logic.
This allows you to separate the meat of your function
from your error handling.
{ return arrayindex;} getElement = wither; ; // Caught: Cannot read property '4' of undefined
As you can see, the original arguments are still accessible in the handler. In this example we've specified the kind of error we want to catch. This means that only TypeErrors will be caught with this function. Other errors will fall through.
before(func, before)
{ console;} doSomething = wither; ; //doSomething called with (1,2,'a') //Something!
after(func, after)
{ console;} doSomething = wither; ; // Something! // DONE!
pre(func, [name], condition)
Throws an error if condition returns false. This error can be caught with a handle
{ return a/b;} divide = wither; divide = wither; ; // Everything is not shiny!;
post(func, [name], condition)
//always returns two return a + b;} add = wither