- SPLessons
SPLessons 5 Steps, 3 Clicks
5 Steps - 3 Clicks Exceptions Exceptions

shape Introduction Exceptions - The data steaming, serialization and the file system for a system is provided by In general computing, I/O means Input or Output. Those methods throw the IOException whenever an input or output operation is failed or interpreted. Note that this won't be thrown for Reading or writing to Memory as Java will be handling it automatically.


shape Table Exceptions Description
IOException This exception represents when failure in I/O occurs.
FileNotFoundException This exception represents that when attempting to open file through specified pathname has failed.
InvalidClassException In serialization run time the class represented with inappropriate the this type of exception throws.
InvalidObjectException This exception throws due to failure of validation of deserialized objects.
InterruptedIOException This exception throws due to interruption in I/O operations.
ObjectStreamException This exception throws due to object stream class.
NotSerializableException This exception throws when the object required to have the serializable interface.
NotActiveException This exception throws when the serialization or deserialization  are not active.
WriteAbortedException Because of during write operation the object stream exception throws.
SyncFailedException This exception throws when synchronisation fails.
UnsupportedEncodingException This exception throws when character encoding is not supported.
CharConversionException This represents the basic class for character conversion exception.

shape Example Exceptions - Following is an example. [java]package; import; import; import; public class IOExceptionExample { private static String filepath = "E:\\splessons.txt"; public static void main(String[] args) { BufferedReader br = null; String curline; try { br = new BufferedReader(new FileReader(filepath)); while ((curline = br.readLine()) != null) { System.out.println(curline); } } catch (IOException e) { System.err.println("An IOException was caught :"+e.getMessage()); } finally{ try { if(br != null) br.close(); } catch (IOException e) { e.printStackTrace(); } } } } [/java] This code is going to give exception that is the given file path is wrong. IOException is a very general exception that occurs when an IO operations fails. So you can understand that there is no standard way on how to solve this exception. The best thing you can do is to explicitly handle the exception in a try-catch block and print out the message of the exception. Then you can take the correct actions to solve this situation. Output The result will be as follows. [java]An IOException was caught :E:\splessons.txt (The system cannot find the file specified)[/java]


shape Key Points

  • Exceptions - The data steaming, serialization and the file system for a system is provided by