Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handling checked exceptions #172

Open
hrstoyanov opened this issue Mar 16, 2024 · 1 comment
Open

Handling checked exceptions #172

hrstoyanov opened this issue Mar 16, 2024 · 1 comment
Labels
enhancement New feature or request
Milestone

Comments

@hrstoyanov
Copy link

hrstoyanov commented Mar 16, 2024

Consider using this (perfectly legit ) java hack :

public interface ExceptionUtils {

    /**
     * Rethrow an {@link java.lang.Throwable} preserving the stack trace but making it unchecked.
     *
     * @param exception to be re-thrown as unchecked.
     */
    static void rethrowUnchecked(final Throwable eexception{
        rethrow(exception);
    }

    @SuppressWarnings("unchecked")
    private static <T extends Throwable> void rethrow(final Throwable t) throws T {
        throw (T) t;
    }

}

This would remove the need for always having to wrap check exceptions such as IORuntimeException and possibly others, preserving a clean stack trace:

try {
    //...
}
catch(IOException e)  {
    // throw new IORuntimeException(e);
    ExceptionUtils.rethrowUnchecked(e);
}
@fh-ms
Copy link
Contributor

fh-ms commented Apr 17, 2024

Good idea to circumvent the checked exception mess.

If we consider using this solution, it would be a breaking change in our APIs. I will add this to the next major release milestone.

@fh-ms fh-ms added this to the 2.0.0 milestone Apr 17, 2024
@hg-ms hg-ms added the enhancement New feature or request label Sep 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants