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

前端 未结 9 1152
忘了有多久
忘了有多久 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:32

    The easiest way is to define your own exception object which extend the RuntimeException class instead of the Exception class.

提交回复
热议问题