https://github.com/astrapi69/throwable
utilities for java throwable objects
https://github.com/astrapi69/throwable
Last synced: 2 months ago
JSON representation
utilities for java throwable objects
- Host: GitHub
- URL: https://github.com/astrapi69/throwable
- Owner: astrapi69
- License: mit
- Created: 2018-12-24T14:23:53.000Z (about 7 years ago)
- Default Branch: develop
- Last Pushed: 2024-06-28T14:08:14.000Z (over 1 year ago)
- Last Synced: 2025-07-20T16:41:20.480Z (6 months ago)
- Language: Java
- Size: 189 KB
- Stars: 5
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: .github/CONTRIBUTING.md
- Funding: .github/FUNDING.yml
- License: LICENSE
- Code of conduct: .github/CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# Overview
[](https://github.com/astrapi69/throwable/actions/workflows/gradle.yml)
[](https://codecov.io/gh/astrapi69/throwable)
[](https://github.com/astrapi69/throwable/issues)
[](https://maven-badges.herokuapp.com/maven-central/io.github.astrapi69/throwable)
[](http://www.javadoc.io/doc/io.github.astrapi69/throwable)
[](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=GVBTWLRAZ7HB8)
[](https://hitsofcode.com/github/astrapi69/throwable/view?branch=develop)
[](https://github.com/astrapi69/throwable)
Project that holds utilities for get the stacktrace as string from java throwable objects and can
decorate checked exceptions and transform them to unchecked exceptions
If you like this project put a ⭐ and donate
> Please support this project by simply putting a Github
Star ⭐
>
> Share this library with friends on Twitter and everywhere else you can
>
> If you love this project [](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=GVBTWLRAZ7HB8)
# Features
- Transform stacktrace object from Throwable(Exceptions, Errors) to String object
- Transform checked exceptions to unchecked exceptions
- Transform checked exceptions to unchecked exceptions in streams
## License
The source code comes under the liberal MIT License, making throwable great for all types of
applications.
## gradle dependency
Replace the variable ${latestVersion} with the current latest version: [](https://maven-badges.herokuapp.com/maven-central/io.github.astrapi69/throwable)
You can first define the version in the ext section and add than the following gradle dependency to
your project `build.gradle` if you want to import the core functionality of throwable:
define version in file gradle.properties
```
throwableVersion=${latestVersion}
```
or in build.gradle ext area
```
throwableVersion = "${latestVersion}"
```
and then add the dependency to the dependencies area
```
implementation("io.github.astrapi69:throwable:$throwableVersion")
```
# with new libs.versions.toml file
If you use the new libs.versions.toml file for new automatic catalog versions update
```
[versions]
throwable-version=${latestVersion}
[libraries]
throwable = { module = "io.github.astrapi69:throwable", version.ref = "throwable-version" }
```
then add the dependency to the dependencies area
```
implementation libs.throwable
```
## Maven dependency
Add the following maven dependency to your project `pom.xml` if you want to import the core
functionality of throwable:
Than you can add the dependency to your dependencies:
...
${latestVersion}
...
...
...
io.github.astrapi69
throwable
${throwable.version}
...
# Usage
You can decorate a method that throws a checked exceptions with the class RuntimeExceptionDecorator
```
public final class FileFactory
{
public static FileCreationState newFile(final File file) throws IOException
{
FileCreationState fileCreationState = FileCreationState.ALREADY_EXISTS;
if (!file.exists())
{
fileCreationState = FileCreationState.FAILED;
newParentDirectories(file);
if (file.createNewFile())
{
fileCreationState = FileCreationState.CREATED;
}
}
return fileCreationState;
}
public static FileCreationState createFile(final File file)
{
return RuntimeExceptionDecorator.decorate(()-> newFile(file));
}
}
```
The above example shows the method FileFactory#newFile that throws a checked IOExceptions. The
method FileFactory#createFile decorates the method FileFactory#newFile with the method decorate of
the utility class RuntimeExceptionDecorator and do not have to declare a throw clause in the method
signature. Note: the method FileFactory#createFile returns a FileCreationState object
```
public final class CopyFileExtensions
{
public static void copyFiles(final List sources, final File destination,
final Charset sourceEncoding, final Charset destinationEncoding, final boolean lastModified)
{
if (!destination.exists())
{
FileFactory.newDirectory(destination);
}
sources.stream().forEach(RuntimeExceptionDecorator.decorate(file -> {
File destinationFile = new File(destination, file.getName());
CopyFileExtensions.copyFile(file, destinationFile, sourceEncoding, destinationEncoding,
lastModified);
}));
}
...
}
```
The method RuntimeExceptionDecorator#decorate is overloaded, so you can use it also for streams as
you can see in the above example. This is provided with the inteface ThrowableConsumer that is a
FunctionalInterface.
## Want to Help and improve it? ###
The source code for throwable are on GitHub. Please feel free to fork and send pull requests!
Create your own fork of [astrapi69/throwable/fork](https://github.com/astrapi69/throwable/fork)
To share your
changes, [submit a pull request](https://github.com/astrapi69/throwable/pull/new/develop).
Don't forget to add new units tests on your changes.
## Contacting the Developers
Do not hesitate to contact the throwable developers with your questions, concerns, comments, bug
reports, or feature requests.
- Feature requests, questions and bug reports can be reported at
the [issues page](https://github.com/astrapi69/throwable/issues).
## Note
No animals were harmed in the making of this library.
# Donations
This project is kept as an open source product and relies on contributions to remain being
developed. If you like this library, please consider a donation
over paypal:
or over bitcoin(BTC) with this address:
bc1ql2y99q7e8psndhcc3gferk03esw3qqf677rhjy

or over FIO with this address:
FIO7tFMUVAA9cHiPPqKMfMXiSxHrbpiFyRYqTketNuM67aULuwjop

or over Ethereum(ETH) with:
0xc057D159D3C8f3311E73568b334FF6fE82EB2b7D

or over Ethereum Classic(ETC) with:
0xF708cA86D86C246B69c3F4BAe431eBbe0c2bfddD

or over Dogecoin(DOGE) with:
D5yi4Um8cpakd6yPRm2hGWuQ5nrVzhSSW1

or over Monero(XMR) with:
49bqeRQ7Bf49oJFVC72pqpe5hFbb62pfXDYPdLsadGGF81KZW2ZfrPZ8PbAVu5X2v1TYAspeczMya3cYQysNS4usRRPQHVw

or over flattr:
## Similar projects
Here is a list of awesome similar projects:
Open Source:
* [throwing-function](https://github.com/pivovarit/throwing-function) Checked Exceptions-enabled
Java 8+ functional interfaces + adapters
* [sneakythrow](https://github.com/rainerhahnekamp/sneakythrow) SneakyThrow is a Java library to
ignore checked exceptions
## Credits
|**Nexus Sonatype repositories**|
| :---: |
|[](https://oss.sonatype.org/index.html#nexus-search;gav~io.github.astrapi69~throwable~~~)|
|Special thanks to [sonatype repository](https://www.sonatype.com) for providing a free maven repository service for open source projects|
|
|
|**codecov.io**|
| :---: |
|[](https://codecov.io/gh/astrapi69/throwable)|
|Special thanks to [codecov.io](https://codecov.io) for providing a free code coverage for open source projects|
|
|
|**javadoc.io**|
| :---: |
|[](http://www.javadoc.io/doc/io.github.astrapi69/throwable)|
|Special thanks to [javadoc.io](http://www.javadoc.io) for providing a free javadoc documentation for open source projects|
|
|