AngularJs Promises Kullanımı

c#taki try catch kullanımınn angulardaki kullanımı diyebiliriz.
// Fiddle – http://jsfiddle.net/EFpn8/6/
f1().then(function(data) {
console.log(“success 1: “+data)
return f2();
})
.then(function(data) {console.log(“success 2: “+data)})
.catch(function(data) {console.log(“error: “+data)});

function f1() {
var deferred = $q.defer();
// An exception thrown here is not caught in catch
// throw “err”;
deferred.resolve(“done f1”);
return deferred.promise;
}

function f2() {
var deferred = $q.defer();
// An exception thrown here is handled properly
throw “err”;
deferred.resolve(“done f2”);
return deferred.promise;
}