Promises, synchronous errors and tests

Synchronous functions are wrapped in a `try..catch` to support synchronous errors and the return function is checked for a promise.