Is there a way to make Runnable's run() throw an exception?

前端 未结 9 1154
忘了有多久
忘了有多久 2020-12-07 14:43

A method I am calling in run() in a class that implements Runnable) is designed to be throwing an exception.

But the Java compiler won\'t let me do that and suggests

9条回答
  •  醉梦人生
    2020-12-07 15:30

    Your requirement doesn't make any sense. If you want to notify the called of the thread about an exception that happened, you could do that through a call back mechanism. This can be through a Handler or a broadcast or whatever else you can think of.

提交回复
热议问题