Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/micheljung/nocatch
Get rid of annoying checked exceptions!
https://github.com/micheljung/nocatch
Last synced: about 2 months ago
JSON representation
Get rid of annoying checked exceptions!
- Host: GitHub
- URL: https://github.com/micheljung/nocatch
- Owner: micheljung
- License: mit
- Created: 2016-02-13T19:31:11.000Z (almost 9 years ago)
- Default Branch: main
- Last Pushed: 2021-06-19T12:49:55.000Z (over 3 years ago)
- Last Synced: 2024-04-24T12:42:02.986Z (8 months ago)
- Language: Java
- Homepage:
- Size: 125 KB
- Stars: 12
- Watchers: 3
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# NoCatch
Get rid of annoying checked exceptions!## Usage
Instead of:
```java
try {
URL url = new URL("http://www.github.com");
// Other code you really don't want in this try-block
} catch (MalformedURLException e) {
throw new RuntimeException(e);
}
```
(or even worse, propagating the exception up your stack)Just write:
```java
import static com.github.nocatch.NoCatch.noCatch;
...
URL url = noCatch(() -> new URL("http://www.github.com"));
```And any checked exception will automatically be wrapped into a runtime exception (`NoCatchException`). Woa!
## Dependency
Gradle:
```groovy
dependencies {
compile 'io.github.micheljung:nocatch:2.0'
}
```### Custom wrapper exception
You can specify your own wrapper exception just like so:
```java
// Throws WrapperException instead of NoCatchException
URL url = noCatch(() -> new URL(";"), WrapperException.class);
```
Make sure your exception has a contructor like `public WrapperException(Throwable cause)`.### Global custom wrapper exception
Want to specify your own wrapper exception globally? No problem:
```java
NoCatch.setDefaultWrapperException(RuntimeException.class);// Throws RuntimeException
noCatch(() -> new URL(";"));
```