catch (onRejection, label) Promise
catch
is simply sugar for then(undefined, onRejection)
which makes it the same as the catch block of a try/catch statement.
function findAuthor(){ throw new Error('couldn't find that author'); } // synchronous try { findAuthor(); } catch(reason) { // something went wrong } // async with promises findAuthor().catch(function(reason){ // something went wrong });
Parameters:
-
onRejection
Function
-
label
String
- optional string for labeling the promise. Useful for tooling.
Returns:
-
Promise
Please login to continue.