Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6132105
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T17:03:38+00:00 2026-05-23T17:03:38+00:00

What I want is a standard JDK class that look like this: interface ExplodingRunnable

  • 0

What I want is a standard JDK class that look like this:

interface ExplodingRunnable {
    void run() throws Exception;
}

Callable is no good, because its call() method is required to return a value, but I need a void.

Runnable is no good, because its run() method doesn’t declare throws Exception.

I sort of need a combination of the two. Any ideas?

EDIT: I should have mentioned that I tried Callable<Void> but it requires you to define a method:

public Void call() {
    // run your code;
    return null; // ugly!
}

I’m looking for something a bit nicer.

Why do I want this?

I’m implementing a standard why of catching “will never happen” Exceptions (they will never happen, but various APIs define their methods throwing Exceptions) and throwing any Exceptions that might occur by wrapping them in an (unchecked) RuntimeException, so the caller can simply pass a “ExplodingRunnable” in and not have to code loads of perfunctory try/catch blocks that will never be exercised.

FINAL EDIT It looks like what I was looking for doesn’t exist. The accepted answer is the closest to “correct”, but it looks like there is no solution to answer the question as asked.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T17:03:39+00:00Added an answer on May 23, 2026 at 5:03 pm

    An interface with only one method, which returns void and throws Exception.

    Among all java and javax classes, only one fits that description:

    package java.lang;
    
    public interface AutoCloseable
    {
        void close() throws Exception;
    }
    

    Well… the word “close” has many meanings…


    You want to surround a bunch of statements with some extra handling, there is no sin to define your own interface here. You may find that your API requires users to learn 4 new phrases

    Util.muckException( new ExplodingRunnable() { public void run() throws Exception
     ^1     ^2                  ^3                             ^4
    

    You can actually cut down two, and user code would look like this

    new MuckException(){ public void run() throws Exception
    {
        statement_1;
        ...
        statement_n;
    }};
    
    public abstract class MuckException
    {
        public abstract run() throws Exception;
    
        public MuckException()
        {
            try{ run(); }
            catch(Exception e){ throw new Error(e); }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to change the standard 3D look of the standard asp.net checkbox to
Many languages have standard repositories where people donate useful libraries that they want others
Say I have a standard Swing component like JSlider, but I want to slightly
I want to modify the standard sharepoint Rich Text Editor control so that I
I want to use a temp directory that will be unique to this build.
I have a standard textbox that I want to perform an action on a
I want to have a standard method of formatting Show More links in my
I want to update/upgrade the standard Leopard install of Sqlite3 to >3.5 to use
I want to create some up and down buttons using the standard button background
I'm using standard Delphi constants DayMonday, etc and I want to convert them to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.