Yes, there is a reason. This allows you to distinguish between types of exceptions.
Assume the following code:
try { // some instructions } catch (MyFirstException firstException) { // Handler for the first exception } catch (MySecondException secondException) { // Handler for the first exception } catch (Exception exception) { // Handler for all other exceptions }
Event, if MyFirstException and MySecondException inherit from Exception and override all methods, you can distinguish them in catch blocks. This way you can have different handlers for both exceptions.
Sandro munda
source share