Last active
July 13, 2020 16:30
-
-
Save okovalov/8a85c75f7c963ca7806220e90fe7b517 to your computer and use it in GitHub Desktop.
Revisions
-
okovalov revised this gist
Jul 13, 2020 . 1 changed file with 0 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -25,4 +25,3 @@ try { } // from https://flaviocopes.com/javascript-custom-errors/ -
okovalov revised this gist
Jul 13, 2020 . 1 changed file with 28 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1 +1,28 @@ class OutOfFuelError extends Error { constructor(message) { super(message) this.name = "OutOfFuelError" } } class FlatTireError extends Error {} try { const car = new Car() //imagine we have a Car object if (!car.fuel) { throw new OutOfFuelError('No fuel!') } if (car.flatTire) { throw new FlatTireError('Flat tire!') } } catch (err) { if (err instanceof OutOfFuelError) { //handle error } else if (err instanceof FlatTireError) { //handle error } } // from https://flaviocopes.com/javascript-custom-errors/ -
okovalov created this gist
Jul 13, 2020 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1 @@