Skip to content

Commit

Permalink
add error handling demo b00tc4mp#51
Browse files Browse the repository at this point in the history
  • Loading branch information
manuelbarzi committed Jul 12, 2024
1 parent 51b7c17 commit 8cbce30
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions stuff/js/error-handling.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
function logic() {
// ...
//throw new TypeError('data is not number')
throw new SyntaxError('data format is wrong')
// ...
}

try {
logic()
} catch (error) {
if (error instanceof TypeError)
alert('WARN! type is not correct')
else if (error instanceof SyntaxError)
alert('FATAL! syntax is not correct')

}

0 comments on commit 8cbce30

Please sign in to comment.