If you want handle return and throw a custom error:
var test = dbCall();
try {
if(test == <dbCall_error_state>) throw "Custom error here.";
}
catch(e) {
alert("Error: " + e);
}
PS You need replace 'dbCall_error_state' with the return error of dbCall.
If you want throw direcly the error returned by dbCall(), conforming to the ECMAScript specification:
try {
dbCall(); // may throw three types of exceptions
} catch (e) {
if (e instanceof TypeError) {
// statements to handle TypeError exceptions
} else if (e instanceof RangeError) {
// statements to handle RangeError exceptions
} else if (e instanceof EvalError) {
// statements to handle EvalError exceptions
} else {
// statements to handle any unspecified exceptions
logMyErrors(e); // pass exception object to error handler
alert("Error: " + e); // or alert it
}
}
You can see detailed info about this here:
https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Statements/try...catch
console.log(test)inside thetrybody?trybody simply replace theconsole.logstatement with a call to this function by passing it thetestvalue as parameter.