I asked around regarding catching checked exceptions in the context of a thread; the accepted answer was to use Callable
s and Future
s.
But I realized that I can simply wrap the "working" method with Anonymous thread and catch the exception as it would be executed without threads.
(The worker's logic was moved from a new class that implemented Callable to the caller class)
class BlaBla{
public void foo(){
Thread th = new Thread(new Runnable() {
public void run() {
try {
doWork();
} catch (MyCheckedException e) {
dosomething();
}
}
});
th.start();
}
public void dowork throws MyCheckedException{
}
Is there any problem with this approach?