The following example shows how to handle multiple exceptions. For example, if the user enters a zero in the second text field and Java tries to divide the first number by the zero, an ArithmeticException exception is raised. So, what if there are two exceptions to deal with i.e: the NumberFormatException and the ArithmeticException. This means there are multiple exceptions to be handled.
The good news is that there is no limit to the number of catch blocks. The catch blocks can be generated for any exception that the program generates.
The below program show how to handle multiple exceptions in java programming.
C:\>jdk1.4\bin>javac HandMulExcepApp.java
C:\>jdk1.4\bin>appletviewer HandMulExcepApp.html
The actionPerformed() in the above code uses two catch program blocks, one each for the NumberFormatException and ArithmeticException exceptions.
No comments:
Post a Comment