JavaScript Custom Errors — exercises and bug fixes
5 hands-on exercises and 5 find-the-bug challenges for the JavaScript Custom Errors lesson. Every one is checked automatically in the browser — write the code, run it, and the tests tell you what still fails.
Exercises(5)
- 1
Create a custom error
easy10 minBuild a ValidationError class and report its name.
- 2
Show it is still an Error
easy10 minReport whether a custom error passes the Error check.
- 3
Carry an extra property
easy10 minAttach the field name and report it with the message.
- 4
Handle your own separately
easy10 minTell a validation problem apart from a real bug.
- 5
Build a small hierarchy
medium10 minShow a NotFoundError is also an AppError.
Find the bug(5)
- 1
Fix the missing super call
easy8 minThe parent constructor must run before this is used, or the error cannot be built.
- 2
Fix the class that does not extend Error
easy8 minWithout extending Error it is just a plain object.
- 3
Fix the missing name
easy8 minWithout setting name the error reports as a plain Error.
- 4
Fix the extra property never stored
easy8 minThe field is accepted but never put on the error.
- 5
Fix the name compared instead of the type
easy8 minComparing names is fragile; instanceof is the proper check.
Ready to write the code?
The editor, the automatic checks and the worked solutions open up with an account.
Open the workspace