File tree Expand file tree Collapse file tree 2 files changed +50
-0
lines changed Expand file tree Collapse file tree 2 files changed +50
-0
lines changed Original file line number Diff line number Diff line change
1
+ 'use strict' ;
2
+
3
+ const sum = async ( a , b ) => {
4
+ if ( typeof ( a ) === 'number' && typeof ( b ) === 'number' ) {
5
+ return a + b ;
6
+ } else {
7
+ return Promise . reject ( new Error ( 'a and b should be numbers' ) ) ;
8
+ }
9
+ } ;
10
+
11
+ sum ( 2 , 3 )
12
+ . then ( data => {
13
+ console . log ( data ) ;
14
+ } )
15
+ . catch ( err => {
16
+ console . log ( err . message ) ;
17
+ } ) ;
18
+
19
+ sum ( 7 , 'A' )
20
+ . then ( data => {
21
+ console . log ( data ) ;
22
+ } )
23
+ . catch ( err => {
24
+ console . log ( err . message ) ;
25
+ } ) ;
Original file line number Diff line number Diff line change
1
+ 'use strict' ;
2
+
3
+ const sum = async ( a , b ) => {
4
+ if ( typeof ( a ) === 'number' && typeof ( b ) === 'number' ) {
5
+ return a + b ;
6
+ } else {
7
+ return Promise . reject ( new Error ( 'a and b should be numbers' ) ) ;
8
+ }
9
+ } ;
10
+
11
+ ( async ( ) => {
12
+
13
+ try {
14
+ console . log ( await sum ( 2 , 3 ) ) ;
15
+ } catch ( e ) {
16
+ console . log ( e . message ) ;
17
+ }
18
+
19
+ try {
20
+ console . log ( await sum ( 7 , 'A' ) ) ;
21
+ } catch ( e ) {
22
+ console . log ( e . message ) ;
23
+ }
24
+
25
+ } ) ( ) ;
You can’t perform that action at this time.
0 commit comments