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
Copy file name to clipboardExpand all lines: README.md
+59-24Lines changed: 59 additions & 24 deletions
Original file line number
Diff line number
Diff line change
@@ -6,13 +6,33 @@ This small library holds a set of Exceptions that implements idea of fast, reusa
6
6
7
7
## Idea
8
8
9
-
The idea is to have a set of simple runtime exceptions. They should always take the field Exception ID (Eid) in the making. This field 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. 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 idea is to use a set of simple runtime exceptions. They should always take the field Exception ID (Eid) in the making. This field 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 identify each single exception. 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.
10
10
11
11
This approach is best to use with tools and plugins like:
12
12
13
13
*[EidGenerator for Netbeans IDE](http://plugins.netbeans.org/plugin/53137/exception-id-eid-generator)
14
14
*[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)
pl.wavesoftware.eid.exceptions.EidIllegalStateException: [20150721:100554]<g0qrwx> => Zipfile in invalid format
26
+
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
27
+
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
28
+
29
+
Caused by: java.util.zip.DataFormatException: Zipfile in invalid format
30
+
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
31
+
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
32
+
... 62 more
33
+
```
34
+
35
+
16
36
## Caution
17
37
18
38
This classes shouldn't be used in any public API or library. It is designed to be used for in-house development of end user applications which will report bugs in standardized error pages or post them to issue tracker.
@@ -35,39 +55,54 @@ Static convenience methods that help a method or constructor check whether it wa
35
55
36
56
Each method accepts a EID string or Eid object, which is designed to ease of use and provide strict ID for given exception usage. This approach speed up development of large application and helps support teams by giving both static and random ID for each possible unpredicted bug.
37
57
38
-
Example:
58
+
Each example uses static import:
39
59
40
60
```java
41
-
/**
42
-
* Returns the positive square root of the given value.
43
-
*
44
-
* @param value value to be square rooted
45
-
* @return the square root of input value
46
-
* @throws EidIllegalArgumentException if the value is negative
`checkArgument` method should be used to check argument of the method, and validate it in technical terms (not business terms).
67
+
68
+
Example:
52
69
53
-
void exampleBadCaller() {
54
-
// will throw EidIllegalArgumentException with "20150718:012333" as ID
55
-
double d = sqrt(-1.0);
70
+
```java
71
+
// [..]
72
+
publicstaticdouble sqrt(double value);
73
+
checkArgument(value >=0.0, "20150718:012333");
74
+
// if ok, calculate the square root
56
75
}
57
76
```
58
77
59
-
In this example, `checkArgument` throws an `EidIllegalArgumentException` to indicate that `exampleBadCaller` made an error in its call to sqrt. Exception, when it will be printed will contain user given EID and also randomly generated ID. Those fields can be displayed to end user on error page on posted directly to issue tracker.
78
+
In this example, `checkArgument` throws an `EidIllegalArgumentException` to indicate that developer made an error in its call to `sqrt`.
79
+
80
+
#### `checkState` method
81
+
82
+
`checkState` method should be used to check state of the class in given moment, and validate it in technical terms (not business terms).
60
83
61
84
Example:
62
85
63
86
```java
64
-
// Main application class for ex.: http servlet
65
-
try {
66
-
performRequest(request, response);
67
-
} catch (EidRuntimeException ex) {
68
-
issuesTracker.putIssue(ex);
69
-
throw ex;
70
-
}
87
+
checkState(a >=3.14&& b <0., "20150721:115016");
88
+
```
89
+
90
+
#### `checkNotNull` method
91
+
92
+
`checkNotNull` method should be used to check if given non null argument is actually `null`
0 commit comments