|
5 | 5 |
|
6 | 6 | > Error handling library for Android and Java |
7 | 7 |
|
| 8 | +Encapsulate error handling logic into objects that adhere to configurable defaults. Then pass them around as parameters or inject them via DI. |
| 9 | + |
8 | 10 | ## Download |
9 | 11 | Download the [latest JAR](https://bintray.com/workable/maven/ErrorHandler/_latestVersion) or grab via Maven: |
10 | 12 | ```xml |
@@ -180,23 +182,15 @@ ErrorHandler is __thread-safe__. |
180 | 182 |
|
181 | 183 |
|
182 | 184 | ## About |
183 | | -A common problem in software, specially in UI software is that of error handling. |
184 | | - |
185 | | -One way to classify errors can be by how they relate to the [problem domain](https://en.wikipedia.org/wiki/Problem_domain). Some errors, like `network` or `database` errors are orthogonal to the problem domain and designate truly **exceptional conditions**, while others are core parts of the domain like `validation` and `authentication` errors. |
186 | | - |
187 | | -Another way to classify errors is by their **scope**. Are they **common** throughout the application or **specific** to a single screen, object or even method? Think of `UnauthorizedException` versus `InvalidPasswordException`. |
188 | | - |
189 | | -And let's not forget another very simple distinction between errors. Those that are known at authoring time and thus **expected** (despite of how probable is that they occur), and those that are **unknown** until runtime. |
190 | 185 |
|
191 | | -With that in mind, we usually want to: |
| 186 | +When designing for errors, we usually need to: |
192 | 187 |
|
193 | | -1. have a **default** handler for every **expected** (exceptional, common or not) error |
194 | | -2. handle **specific** errors **as appropriate** based on where and when they occur |
195 | | -3. have a **default** catch-all handler for **unknown** errors |
196 | | -4. **override** any default handler if needed |
197 | | -5. keep our code **DRY** |
| 188 | +1. have a **default** handler for every **expected** error (i.e. network, subscription errors) |
| 189 | +2. handle **specific** errors **as appropriate** based on where and when they occur (i.e. network error while uploading a file, invalid login) |
| 190 | +3. have a **catch-all** handler for **unknown** errors (i.e. system libraries runtime errors we don't anticipate) |
| 191 | +4. keep our code **DRY** |
198 | 192 |
|
199 | | -Java, as a language, provides you with a way to do the above. By mapping exceptional or very common errors to runtime exceptions and catching them lower in the call stack, while having specific expected errors mapped to checked exceptions and handle them near where the error occurred. Still, countless are the projects where this simple strategy has gone astray with lots of errors being either swallowed or left for the catch-all `Thread.UncaughtExceptionHandler`. Moreover, it usually comes with significant boilerplate code. `ErrorHandler` however eases this practice through its fluent API, error aliases and defaults mechanism. |
| 193 | +Java, as a language, provides you with a way to do the above. By mapping cross-cutting errors to runtime exceptions and catching them lower in the call stack, while having specific expected errors mapped to checked exceptions and handle them near where the error occurred. Still, countless are the projects where this simple strategy has gone astray with lots of errors being either swallowed or left for the catch-all `Thread.UncaughtExceptionHandler`. Moreover, it usually comes with significant boilerplate code. `ErrorHandler` however eases this practice through its fluent API, error aliases and defaults mechanism. |
200 | 194 |
|
201 | 195 | This library doesn't try to solve Java specific problems, although it does help with the `log and shallow` anti-pattern as it provides an opinionated and straightforward way to act inside every `catch` block. It was created for the needs of an Android app and proved itself useful very quickly. So it may work for you as well. If you like the concept and you're developing in _Swift_ or _Javascript_, we're baking 'em and will be available really soon. |
202 | 196 |
|
|
0 commit comments