Saturday, December 3, 2011

Common exceptions in java language

In java programming, daily coding, we have encountered different exceptions, so I am listing out the list of common exceptions, and the scenarios, how to solve those exceptions.

following are the exceptions in java programming language. 


One common exception occurred, This will happens when you are calling the object's method with the object is not created or not initialized properly.

String str=null; System.out.println(str.toString());

the solution in our code is

if(str==null){ //initialize the string object here }else{ System.out.println(str.toString()); }

ClassCastException error

This exception occurs if we assign the incorrect object.

NumberFormatException error

This exception has occurred if we convert the string data items to number items format object.

SocketTimeoutException error

This exception occurred when dealing with sockets communication between client and server. server not accepting sockets accept/read operations

OutOfMemoryException issue:-

This issue occurs when an object exists on heap memory is full. The fix is either increase heap memory or fine tune the code to minimize object creation.


Note: Only a member of this blog may post a comment.