You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This small library holds a set of exceptions and utilities that implements idea of fast, reusable, error codes that can be simply thrown fast in case of unpredictable and unrecoverable application failure. It is meant to be used for application bugs.
6
6
7
-
## Idea
7
+
## The Idea
8
8
9
-
The idea is to use a set of simple runtime exceptions. They should always take the Exception ID (Eid) object in the making. This eid object will then be reported when displaying or logging that exception. It can also be viewed on the professional fatal error window of the application as a bug reference. EidRuntimeExceptions contains also additional unique ID to distinguish each single exception from others with same Eid. This approach simplifies the management of exceptions in the application and allows developers to focus on functionalities rather than coming up with the correct statement for the exception.
9
+
The main idea of this library is to use a set of simple runtime exceptions to speedup development and make it more professional in the same time. Those exceptions should always take the Exception ID (Eid for short) object on construction. The Eid object should be generated by developer while writing code and committed in the constructor of an exception. This eid object will then be reported when that exception is being displayed or logged.
10
10
11
-
This approach is best to use with tools and plugins like:
11
+
This approach simplifies the management of exceptions in the application and allows developers to focus on functionality and code quality, rather than coming up with the correct statement for the exception.
12
+
13
+
This error number is perfect to be displayed on the error "500" page for your application as a bug reference. It's good idea, because it is static, so wil l not change in subsequent invocations, but it also do not disclose the actual reason why bug occurred.
14
+
15
+
This approach is best to use with tools and IDE plugins like:
12
16
13
-
*[EidGenerator for Netbeans IDE](http://plugins.netbeans.org/plugin/53137/exception-id-eid-generator)
14
17
*[Generating Exception Id number in Intellij IDEA with Live Templates](https://github.com/wavesoftware/java-eid-exceptions/wiki/Generating%20Exception%20Id%20number%20in%20Intellij%20IDEA%20with%20Live%20Templates)
18
+
*[EidGenerator for Netbeans IDE](http://plugins.netbeans.org/plugin/53137/exception-id-eid-generator)
19
+
20
+
Error page can say something like:
21
+
22
+
> We are deeply sorry. A fatal error occurred.
23
+
> The reference number is: 20150721:100554
24
+
>
25
+
> Wait a couple of minutes, and try again. If the same error number persists, call IT support.
26
+
27
+
That error page is easy to implement, because all those exceptions implement `EidContainer` interface.
15
28
16
29
Example:
17
30
@@ -43,7 +56,7 @@ This classes shouldn't be used in any public API or library. It is designed to b
From release `1.1.0` there have been added methods to support additional formatted messages for `checkArgument`, `checkState`, `checkNotNull` and `checkElementIndex` method. Those method versions can sometimes be used to pass additional information to exceptions that will be displayed in log files.
123
+
From release `1.2.0` methods have been added to support additional formatted messages for `checkArgument`,
124
+
`checkState`, `checkNotNull` and `checkElementIndex` method. Those method versions can sometimes be used to pass additional information to exceptions that will be displayed in log files.
111
125
112
-
Message formatting is done using `String.format(String, Object[])` method.
126
+
From release `2.0.0` message formatting is done using `MessageFormat#format(String, Object[])` method.
InputStream is = tryToExecute(() -> { resource("project.properties"); }, "20150718:121521");
150
-
```
151
-
152
174
#### Logging
153
175
154
-
Eid object can also be useful in logging. That are `makeLogMessage` method provided to do that. Message formatting is done using `String.format(String, Object[])` method.
176
+
Eid object can also be useful in logging. That is `message` method provided to do that. Message formatting is done using
In that file, place a fully qualified class name of your class that implements `Configurator` interface. It should be called first time you reference an Eid, or and of the eid exceptions, or utility preconditions class.
206
+
207
+
##### Programmatic configuration
208
+
209
+
You can also configure Eid library programmatically. To do just that, use `EidModule.getBinding().getConfigurationSystem().configure()` method.
210
+
211
+
```java
212
+
// configure
213
+
Configurator original =EidModul.getBinding()
214
+
.getConfigurationSystem()
215
+
.configure(configuration ->
216
+
configuration.uniqueIdGenerator(() -> constUniq)
217
+
);
218
+
219
+
// restore original configuration with:
220
+
EidModule.getBinding()
221
+
.getConfigurationSystem()
222
+
.configure(original);
223
+
```
224
+
225
+
Note, that method returns a configurator that can be used to restore configuration to the state before you invoke this configuration method.
226
+
227
+
#### Validation
228
+
229
+
On `2.0.0` release optional validation have been added. If you configure a `Validator` using either of configuration methods, each new Eid will be validated for correctness. Note that this will happen lazily for `EidPreconditions` and `EidExecutions` utility methods.
230
+
231
+
### Contributing
168
232
169
233
Contributions are welcome!
170
234
@@ -184,6 +248,17 @@ Even if you can't contribute code, if you have an idea for an improvement please
184
248
185
249
### Releases
186
250
251
+
- 2.0.0
252
+
- Complete overhaul of library structure
253
+
- More obvious exceptions constructors
254
+
- Better configuration
255
+
- Optional validation
256
+
257
+
- 1.2.0
258
+
- Major performance tweaks and tests for `EidPreconditions` methods #4
259
+
- Major performance tweaks and tests for `Eid` class #2
260
+
- Switched to new OSSRH maven template
261
+
- Switched to Git Flow via jgitflow plugin
187
262
- 1.1.0
188
263
- Adding support for formatted messages in exceptions and also in utility methods of `EidPreconditions`
0 commit comments