In some code I’ve been reading, I’ve come across this :
class Someclass
{
public static void main(String[] args) throws IOException
{
//all other code here......
}
}
If main() throws an exception, in this case its an IOException, where is it caught and handled?
EDIT:
Is this considered bad practice? Or is this really common in real world code?
The detailed flowchart of full uncaught exception handling is given here: How uncaught exceptions are handled in Java.
Therefore you can, if you wish to, create your own custom uncaught exception handler.
It should also be noted that while
mainis commonly used as a Java application entry point, the method is just like any other methods in that it can also be called from other contexts (e.g. othermainmethods, or even itself recursively!). In that case, the caller can catch exceptions thrown.Output: