Practice ยท 2 of 3
Custom ValidationError
Define class ValidationError extends Error with name set to "ValidationError". Write validateAge(age) that THROWS a ValidationError with message "age must be a number" when age is not a number (or is NaN), and "age must be non-negative" when it is below 0. Write tryValidateAge(age) that RETURNS { ok: true, value: age } on success and { ok: false, error } when a ValidationError was thrown โ any other error must still propagate.
Difficulty: intermediate
Press Submit to check your solution.
Back to lesson: Practice: Error Handling โ Practice