Simply put, this is not possible ; you cannot determine whether someone will attach a handler at some point in the future in the same way you cannot tell if this will be caught externally or not when throw in a function. However, what you want to do can be done .
This is not a "noob" question, and it is very fundamental:
function foo() throw new Error(); // I want to know if whoever is calling `foo` // handles this error }
First thing you can do
Simply put, in the first case:
exampleOne.$promise.then(function (success) {}, function (error) {});
What you receive is a promise that is always fulfilled. However, in the second case, the promise may be rejected. Handling a reject using the reject handler is similar to catch in real code - once you process it, it will no longer be rejected.
Personally, I would not use the interceptor here, but rather use the resource, since this was more clear with the intention, you can wrap it in a function so that it does not need scope, but I like this idea less. Here is what I would do
attempt(function(){ return $resource('/path').save(objectTwo).$promise. then(function (success) {}); }); function attempt(fn){ var res = fn(); res.catch(function(err){
Now, a short proof that this cannot be done.
We prove it for pleasure.
Say we are assigned the program code M, we create a new promise p and replace each return in M and throw in M using return p.catch(function(){}) , and also add a return p.catch(function(){}) , now the handler will be added to p if and only if M is executed. Thus, in the short given code M, we built a way to see if it stops based on the existence of a solution to the search problem if catch added to p - so this problem is at least as complex as the stop problem .