Skip to content

Latest commit

 

History

History
261 lines (192 loc) · 9.89 KB

README.md

File metadata and controls

261 lines (192 loc) · 9.89 KB

Overview

Java CI with Gradle Coverage Status Open Issues Maven Central Javadocs Donate Hits Of Code Lines Of Code

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 donation

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.

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:

<properties>
        ...
    <!-- THROW-ABLE version -->
    <throwable.version>2.3</throwable.version>
        ...
</properties>
        ...
    <dependencies>
        ...
        <!-- THROW-ABLE DEPENDENCY -->
        <dependency>
            <groupId>io.github.astrapi69</groupId>
            <artifactId>throwable</artifactId>
            <version>${throwable.version}</version>
        </dependency>
        ...
    </dependencies>

gradle dependency

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=2.3

or in build.gradle ext area

    throwableVersion = "2.3"

and then add the dependency to the dependencies area

    implementation("io.github.astrapi69:throwable:$throwableVersion")

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<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.

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

To share your changes, submit a pull request.

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.

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:

PayPal this

or over bitcoin(BTC) with this address:

bc1ql2y99q7e8psndhcc3gferk03esw3qqf677rhjy

Donation Bitcoin Wallet

or over FIO with this address:

FIO7tFMUVAA9cHiPPqKMfMXiSxHrbpiFyRYqTketNuM67aULuwjop

Donation FIO Wallet

or over Ethereum(ETH) with:

0xc057D159D3C8f3311E73568b334FF6fE82EB2b7D

Donation Ethereum Wallet

or over Ethereum Classic(ETC) with:

0xF708cA86D86C246B69c3F4BAe431eBbe0c2bfddD

Donation Ethereum Classic Wallet

or over Dogecoin(DOGE) with:

D5yi4Um8cpakd6yPRm2hGWuQ5nrVzhSSW1

Donation Dogecoin Wallet

or over Monero(XMR) with:

49bqeRQ7Bf49oJFVC72pqpe5hFbb62pfXDYPdLsadGGF81KZW2ZfrPZ8PbAVu5X2v1TYAspeczMya3cYQysNS4usRRPQHVw

Donation Monero Wallet

or over flattr:

Flattr this

Similar projects

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

Credits

Nexus Sonatype repositories
sonatype repository
Special thanks to sonatype repository for providing a free maven repository service for open source projects
codecov.io
Coverage Status
Special thanks to codecov.io for providing a free code coverage for open source projects
javadoc.io
Javadocs
Special thanks to javadoc.io for providing a free javadoc documentation for open source projects