GeezerVison is showing github.com — Refactor: fail fast · HowProgrammingWorks/Errors@420e090
File tree
Expand file treeCollapse file tree
Open diff view settings
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: JavaScript/1-sync-try.js +1-2Lines changed: 1 addition & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
|
3 | 3 | const sum = (a, b) => { |
4 | 4 | if (typeof a === 'number' && typeof b === 'number') { |
5 | 5 | return a + b; |
6 | | - } else { |
7 | | - throw new Error('a and b should be numbers'); |
8 | 6 | } |
| 7 | + throw new Error('a and b should be numbers'); |
9 | 8 | }; |
10 | 9 |
|
11 | 10 | try { |
|
Collapse file
Copy file name to clipboardExpand all lines: JavaScript/2-sync-tuple.js +1-2Lines changed: 1 addition & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
|
3 | 3 | const sum = (a, b) => { |
4 | 4 | if (typeof a === 'number' && typeof b === 'number') { |
5 | 5 | return [null, a + b]; |
6 | | - } else { |
7 | | - return [new Error('a and b should be numbers')]; |
8 | 6 | } |
| 7 | + return [new Error('a and b should be numbers')]; |
9 | 8 | }; |
10 | 9 |
|
11 | 10 | console.log(sum(2, 3)); |
|
Collapse file
Copy file name to clipboardExpand all lines: JavaScript/4-uncaught.js +1-3Lines changed: 1 addition & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -8,11 +8,9 @@ process.on('uncaughtException', (err) => { |
8 | 8 | const sum = (a, b) => { |
9 | 9 | if (typeof a === 'number' && typeof b === 'number') { |
10 | 10 | return a + b; |
11 | | - } else { |
12 | | - throw new Error('a and b should be numbers'); |
13 | 11 | } |
| 12 | + throw new Error('a and b should be numbers'); |
14 | 13 | }; |
15 | 14 |
|
16 | 15 | console.log(sum(2, 3)); |
17 | | - |
18 | 16 | console.log(sum(7, 'A')); |
Collapse file
Copy file name to clipboardExpand all lines: JavaScript/6-async-await.js +1-2Lines changed: 1 addition & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
|
3 | 3 | const sum = async (a, b) => { |
4 | 4 | if (typeof a === 'number' && typeof b === 'number') { |
5 | 5 | return a + b; |
6 | | - } else { |
7 | | - throw new Error('a and b should be numbers'); |
8 | 6 | } |
| 7 | + throw new Error('a and b should be numbers'); |
9 | 8 | }; |
10 | 9 |
|
11 | 10 | (async () => { |
|