I want to know how to throw exception in run() method of interface Runnable. Since there is no throwable exception declared in run() method of interface Runnable in Java API specification.
Ans:Why would you want to?
I can't see any advantage. Exiting the run method will end the thread. Exiting with an exception will do the same (for instance if you were to throw a RuntimeException).
If you want some other thread to be informed of the error then just pass a message as normal (call a method to alter some state and notify other threads).
I can't see any advantage. Exiting the run method will end the thread. Exiting with an exception will do the same (for instance if you were to throw a RuntimeException).
If you want some other thread to be informed of the error then just pass a message as normal (call a method to alter some state and notify other threads).
No comments:
Post a Comment