485
485
* // No callbacks registered on promise -> unhandled rejection
486
486
* promise.rejected(Error('boom'));
487
487
* flow.execute(function() { console.log('this will never run'); });
488
- * }).thenCatch (function(e) {
488
+ * }).catch (function(e) {
489
489
* console.log(e.message);
490
490
* });
491
491
* // boom
497
497
* promise.rejected(Error('boom'));
498
498
* flow.execute(function() { console.log('a'); }).
499
499
* then(function() { console.log('b'); });
500
- * }).thenCatch (function(e) {
500
+ * }).catch (function(e) {
501
501
* console.log(e.message);
502
502
* });
503
503
* // boom
508
508
* flow.execute(function() {
509
509
* promise.rejected(Error('boom'));
510
510
* return flow.execute(someOtherTask);
511
- * }).thenCatch (function(e) {
511
+ * }).catch (function(e) {
512
512
* console.log(e.message);
513
513
* });
514
514
* // boom
521
521
* flow.execute(function() {
522
522
* promise.rejected(Error('boom1'));
523
523
* promise.rejected(Error('boom2'));
524
- * }).thenCatch (function(ex) {
524
+ * }).catch (function(ex) {
525
525
* console.log(ex instanceof promise.MultipleUnhandledRejectionError);
526
526
* for (var e of ex.errors) {
527
527
* console.log(e.message);
542
542
* flow.execute(function() {
543
543
* promise.rejected(Error('boom'));
544
544
* subTask = flow.execute(function() {});
545
- * }).thenCatch (function(e) {
545
+ * }).catch (function(e) {
546
546
* console.log(e.message);
547
547
* }).then(function() {
548
548
* return subTask.then(
564
564
* throw Error('fail!');
565
565
* });
566
566
* });
567
- * }).thenCatch (function(e) {
567
+ * }).catch (function(e) {
568
568
* console.log(e.message);
569
569
* });
570
570
* // fail!
@@ -920,7 +920,7 @@ promise.Thenable = goog.defineClass(null, {
920
920
* }
921
921
*
922
922
* // Asynchronous promise API:
923
- * doAsynchronousWork().thenCatch (function(ex) {
923
+ * doAsynchronousWork().catch (function(ex) {
924
924
* console.error(ex);
925
925
* });
926
926
*
@@ -931,6 +931,18 @@ promise.Thenable = goog.defineClass(null, {
931
931
* resolved with the result of the invoked callback.
932
932
* @template R
933
933
*/
934
+ catch : function ( errback ) { } ,
935
+
936
+ /**
937
+ * An alias for {@link #catch()}
938
+ *
939
+ * @param {function(*): (R|IThenable<R>) } errback The
940
+ * function to call if this promise is rejected. The function should
941
+ * expect a single argument: the rejection reason.
942
+ * @return {!promise.Promise<R> } A new promise which will be
943
+ * resolved with the result of the invoked callback.
944
+ * @template R
945
+ */
934
946
thenCatch : function ( errback ) { } ,
935
947
936
948
/**
@@ -1247,9 +1259,14 @@ promise.Promise = goog.defineClass(null, {
1247
1259
} ,
1248
1260
1249
1261
/** @override */
1250
- thenCatch : function ( errback ) {
1262
+ catch : function ( errback ) {
1251
1263
return this . addCallback_ (
1252
- null , errback , 'thenCatch' , promise . Promise . prototype . thenCatch ) ;
1264
+ null , errback , 'catch' , promise . Promise . prototype . catch ) ;
1265
+ } ,
1266
+
1267
+ /** @override */
1268
+ thenCatch : function ( errback ) {
1269
+ return this . catch ( errback ) ;
1253
1270
} ,
1254
1271
1255
1272
/** @override */
@@ -1419,6 +1436,14 @@ promise.Deferred = goog.defineClass(null, {
1419
1436
return this . promise . then ( opt_cb , opt_eb ) ;
1420
1437
} ,
1421
1438
1439
+ /**
1440
+ * @override
1441
+ * @deprecated Use {@lcode catch} from the promise property directly.
1442
+ */
1443
+ catch : function ( opt_eb ) {
1444
+ return this . promise . catch ( opt_eb ) ;
1445
+ } ,
1446
+
1422
1447
/**
1423
1448
* @override
1424
1449
* @deprecated Use {@code thenCatch} from the promise property directly.
@@ -1484,7 +1509,7 @@ promise.delayed = function(ms) {
1484
1509
key = null ;
1485
1510
fulfill ( ) ;
1486
1511
} , ms ) ;
1487
- } ) . thenCatch ( function ( e ) {
1512
+ } ) . catch ( function ( e ) {
1488
1513
clearTimeout ( key ) ;
1489
1514
key = null ;
1490
1515
throw e ;
@@ -2992,7 +3017,7 @@ promise.isGenerator = function(fn) {
2992
3017
* yield promise.delayed(250).then(function() {
2993
3018
* throw Error('boom');
2994
3019
* });
2995
- * }).thenCatch (function(e) {
3020
+ * }).catch (function(e) {
2996
3021
* console.log(e.toString()); // Error: boom
2997
3022
* });
2998
3023
*
0 commit comments