-1
import java.util.concurrent.Callable;
import java.io.IOException;

public class HelloWorld{

 public static void main(String []args){
    Callable<Void> callable = new Callable<Void>()
    {
        public Void call() throws IOException
        {
            return null;
        }

    };
    try
    {
        callable.call();
    }
    catch(IOException e)
    {}
 }
}

Here I get error "unreported exception Exception". I don't want to use generic exception Exception. What to do?

YoungHobbit
  • 13,254
  • 9
  • 50
  • 73
  • The `call()` is defined with `call() throws Exception`, so you can change any thing there. Because everything else will be sub type of `Exception` class. – YoungHobbit Dec 22 '15 at 16:57

1 Answers1

2

The Callable interface explicitly declares that the call() method may throw any Exception. If you use the interface, you must catch the exception.

If you aren't using executors, you might be able to define your own interface:

public interface IOTask
{
    public void call() throws IOException;
}

And instead of making a callable, make an IOTask instead.

Andrew Williamson
  • 8,299
  • 3
  • 34
  • 62