I have a customException.js
script with the following service:
app.service('CustomException', function() {
this.CustomException1 = function (message) {
if (!message) {
message = "Custom Exception 1 occurred!";
}
return {
name: 'CustomException1',
message: message
};
}
});
Now I implement this in another service:
app.service('Operations', ['CustomException', function(CustomException) {
this.operation1 = function(param1, param2) {
if (!param1) {
throw new CustomException.CustomException1("Parameter 1 is not defined!");
} else if (!param2) {
throw new CustomException.CustomException1("Parameter 2 is not defined!");
} else {
// code to perform the operation.
}
}
}])
However, when I utilize the Operations
service in a controller without providing the required parameters, my custom exceptions are not caught. No error messages are displayed on the console. The data simply does not show up on the screen. What could be the issue here, and is there a more efficient way to handle custom exceptions in AngularJS?