+ 2
In what situations is the throws keyword useful?
I understand the syntax and that I can pass over exceptions manually using throws and throw,however in what situations is this ACTUALLY of use? Thanks a lot :)
2 odpowiedzi
+ 2
You might have some utility method which throws an exception, if the method signature includes a throws statement for a checked exception then it must be dealt with higher up the call chain. You probably want the higher level method to deal with it.
For example, suppose you have a UI built in Java. When you click on a button it calls some method which has a catch block for various exceptions to send error messages to the UI. An exception is thrown up the call chain and caught in the top method to display the error nicely