Posts

Showing posts from May, 2016

Problem without exception handling in java

Image
Problem without exception handling Following is the simple program with divide by zero situation(ArithmeticException- click here   to know how Arithmetic Exception occurs)We didnt apply exception handling technique. class Simple { public static void main ( String args [ ] ) { int data= 50 / 0 ; System . out . println ( "some code" ) ; } }  Output: Exception in thread main java.lang.ArithmeticException:/ by zero As observed in the output,The statement "some code" is not printed. In the above program ArithmeticException exception is occurred and the exception is not handled hence it is handled by jvm.In this situation JVM will terminate the program and prints the cause for termination. Note: The following lines after the exception are not printed if the exception is not handled properly. Solution by exception handling: Below is the solution,In this program we have applied try and catch. We have enclosed the doubtful code which migh