Skip to content

Commit da2904a

Browse files
committed
README.md updates
1 parent af6cb3e commit da2904a

File tree

3 files changed

+96
-14
lines changed

3 files changed

+96
-14
lines changed

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@
186186
same "printed page" as the copyright notice for easier
187187
identification within third-party archives.
188188

189-
Copyright {yyyy} {name of copyright owner}
189+
Copyright 2015 Wave Software
190190

191191
Licensed under the Apache License, Version 2.0 (the "License");
192192
you may not use this file except in compliance with the License.

README.md

Lines changed: 85 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,85 @@
1-
# java-eid-exceptions
2-
EID Runtime Exceptions and Utilities
1+
# EID Runtime Exceptions and Utilities
2+
This small library holds a set of Exceptions that implements idea of fast, reusable, error codes that can be simple thrown fast in case of unpredictable and unrecoverable application failure.
3+
4+
## Caution
5+
6+
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 standarized error pages or post them to issue tracker.
7+
8+
## Requirements
9+
10+
* JDK >= 1.6
11+
12+
## Maven
13+
14+
```xml
15+
<dependency>
16+
<groupId>pl.wavesoftware</groupId>
17+
<artifactId>eid-exceptions</artifactId>
18+
<version>0.1.0</version>
19+
</dependency>
20+
```
21+
22+
### `EidPreconditions` class
23+
24+
#### General use
25+
26+
Static convenience methods that help a method or constructor check whether it was invoked correctly (whether its preconditions have been met). These methods generally accept a `boolean` expression which is expected to be `true` (or in the case of `checkNotNull`, an object reference which is expected to be non-null). When `false` (or `null`) is passed instead, the `EidPreconditions` method throws an unchecked exception, which helps the calling method communicate to its caller that that caller has made a mistake.
27+
28+
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.
29+
30+
This approach is best to use with tools and plugins like [EidGenerator for Netbeans IDE](http://plugins.netbeans.org/plugin/53137/exception-id-eid-generator)
31+
32+
Example:
33+
34+
```java
35+
/**
36+
* Returns the positive square root of the given value.
37+
*
38+
* @param value value to be square rooted
39+
* @return the square root of input value
40+
* @throws EidIllegalArgumentException if the value is negative
41+
*/
42+
public static double sqrt(double value) {
43+
EidPreconditions.checkArgument(value >= 0.0, "20150718:012333");
44+
// calculate the square root
45+
}
46+
47+
void exampleBadCaller() {
48+
// will throw EidIllegalArgumentException with "20150718:012333" as ID
49+
double d = sqrt(-1.0);
50+
}
51+
```
52+
53+
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.
54+
55+
Example:
56+
57+
```java
58+
// Main application class for ex.: http servlet
59+
try {
60+
performRequest(request, response);
61+
} catch (EidRuntimeException ex) {
62+
issuesTracker.putIssue(ex);
63+
throw ex;
64+
}
65+
```
66+
67+
#### Functional try to execute blocks
68+
69+
Using functional blocks to handle operations, that are intended to operate properly, simplify the code and makes it more readable. It's also good way to deal with untested, uncovered `catch` blocks. It's easy and gives developers nice way of dealing with countless operations that supose to work as intended.
70+
71+
Example:
72+
73+
```java
74+
InputStream is = EidPreconditions.tryToExecute(new RiskyCode<InputStream>() {
75+
@Override
76+
public InputStream execute() throws IOException {
77+
return this.getClass().getClassLoader()
78+
.getResourceAsStream("project.properties");
79+
}
80+
}, "20150718:121521");
81+
```
82+
83+
### Releases
84+
85+
- 0.1.0 (idea imported from Guava Library and COI code)

src/main/java/pl/wavesoftware/eid/utils/EidPreconditions.java

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -71,33 +71,32 @@
7171
* <pre>
7272
*
7373
* {@code
74-
* // Main application class for ex.: servlet
74+
* // Main application class for ex.: http servlet
7575
* try {
7676
* performRequest(request, response);
77-
* } catch (RuntimeException ex) {
78-
* if (ex instanceof EidRuntimeException) {
79-
* issuesTrackerService.put((EidRuntimeException) ex)
80-
* }
77+
* } catch (EidRuntimeException ex) {
78+
* issuesTracker.put(ex);
8179
* throw ex;
8280
* }
8381
* }</pre>
8482
*
8583
*
86-
* <h3>Using easier functional exception blocks</h3>
84+
* <h3>Functional try to execute blocks</h3>
8785
*
8886
* <p>
89-
* Using of functional blocks to handle operations that are inteaded to operate properly is easy and gives developers nise way of
87+
* Using functional blocks to handle operations, that are intended to operate properly, simplify the code and makes it more
88+
* readable. It's also good way to deal with untested, uncovered {@code catch} blocks. It's easy and gives developers nice way of
9089
* dealing with countless operations that supose to work as intended.
9190
*
9291
* <p>
9392
* Example:
9493
* <pre><code>
9594
*
96-
* Document doc = EidPreconditions.tryToExecute({@code new RiskyCode<Document>}() {
95+
* InputStream is = EidPreconditions.tryToExecute({@code new RiskyCode<InputStream>}() {
9796
* {@literal @}Override
98-
* public Document execute() throws SAXException, IOException {
99-
* DocumentBuilder docBuilder = ...
100-
* return docBuilder.parse(new InputSource(reader));
97+
* public InputStream execute() throws IOException {
98+
* return this.getClass().getClassLoader()
99+
* .getResourceAsStream("project.properties");
101100
* }
102101
* }, "20150718:121521");
103102
* </code></pre>

0 commit comments

Comments
 (0)