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
- Transform stacktrace object from Throwable(Exceptions, Errors) to String object
- Transform checked exceptions to unchecked exceptions
- Transform checked exceptions to unchecked exceptions in streams
The source code comes under the liberal MIT License, making throwable great for all types of applications.
Replace the variable ${latestVersion} with the current latest version:
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")
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
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:
<properties>
...
<!-- THROW-ABLE version -->
<throwable.version>${latestVersion}</throwable.version>
...
</properties>
...
<dependencies>
...
<!-- THROW-ABLE DEPENDENCY -->
<dependency>
<groupId>io.github.astrapi69</groupId>
<artifactId>throwable</artifactId>
<version>${throwable.version}</version>
</dependency>
...
</dependencies>
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<File> 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.
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
To share your changes, submit a pull request.
Don't forget to add new units tests on your changes.
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.
No animals were harmed in the making of this library.
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:
Here is a list of awesome similar projects:
Open Source:
- throwing-function Checked Exceptions-enabled Java 8+ functional interfaces + adapters
- sneakythrow SneakyThrow is a Java library to ignore checked exceptions
Nexus Sonatype repositories |
---|
Special thanks to sonatype repository for providing a free maven repository service for open source projects |
codecov.io |
---|
Special thanks to codecov.io for providing a free code coverage for open source projects |
javadoc.io |
---|
Special thanks to javadoc.io for providing a free javadoc documentation for open source projects |