Ember-exex: Exceptional Exceptions for ambitious applications
_____ _
| ____|_ __ ___ | |__ ___ _ __ _____ _______ __
| _| | '_ ` _ \| '_ \ / _ \ '__|____ / _ \ \/ / _ \ \/ /
| |___| | | | | | |_) | __/ | |_____| __/> < __/> <
|_____|_| |_| |_|_.__/ \___|_| \___/_/\_\___/_/\_\
Ember Exceptional Exceptions: Customizable error classes and error re-throwing with original error included
Why ember exex
When building advanced javascript application full featured error handling is required, but unfortunately it is not provided in javascript out of the box. Taste flavor of Java like exceptions in javascript:
- Custom error classes
- Re-throwing of an error with additional context and original error
- Additonal tooling
Console example
Compatiblity
Install
ember install ember-exex
Multiple error classes with inheritance
; const ApplicationError = ; const ServiceError = ; const UserInterfaceError = ; try throw ; catch e console; // true console; // true console; // true console; // false if e instanceof UserInterfaceError ; else if e instanceof ServiceError ; else if e instanceof ApplicationError ; else if e instanceof Error ;
Re-throwing error with wrapped catched error
; const DatabaseError = ; const UserInterfaceError = ; try throw 'Database IO error' catch e throw 'Cannot render user interface' ;
Wrapped error is included as string in error.stack
and stored as property on wrapping error error.previous
Parametrized error messages
; const DatabaseError = ; try throw params: db: 'mydb' table: 'posts'; catch e console; // Database IO error at 'posts' in 'mydb'
Extending errors
; const ServiceError = ; try throw ; catch e if e instanceof ServiceError e; else // do something else