Namespace: Basic:attempt

Basic:attempt

Source:

Methods

attempt(closure) → {Boolean}

Attempt to compute contents of closure and catch all occurring exceptions. The boolean result tells you if the operation was successful or not.

This is most helpful, when used to test value conversions or other atomic/singluar operations, where it just is important if something isolated works or not.

Do not encapsulate complex code in the closure and mind recursively occurring exceptions!

Parameters:
Name Type Description
closure function

the code to test

Source:
Throws:

error if closure is not a function

Returns:
true if no exception occurred
Type
Boolean
Example
if( !attempt(function(){ foobar(); }) ){ console.log('foobar cannot be executed!'); }