Streth
0
Q:

js throw error

throw new Error('Whoops!')
11
var someNumber = 1;
try {
  someNumber.replace("-",""); //You can't replace a int
} catch(err) {
 console.log(err);
}
22
  if (..condition..) {
    throw 'Error message';
  }
3
throw new Error("Error message here"); // Uncaught Error: Error message here
3
FactoryController.prototype.create = function (callback) {
    //The throw is working, and the exception is returned.
    throw new Error('An error occurred'); //outside callback 
    try {
        this.check(function (check_result) {
            callback(check_result);
        });
    } catch (ex) {
        throw new Error(ex.toString());
    }
}

FactoryController.prototype.create = function (callback) {
    try {
        this.check(function (check_result) {
            //The throw is not working on this case to return the exception to the caller(parent)
            throw new Error('An error occurred'); //inside callback 
        });
    } catch (ex) {
        throw new Error(ex.toString());
    }
}
1
throw new Error("message");
0
try {
console.log('hello');
}
catch (e){
}
-1

New to Communities?

Join the community