Solved

Java Exception handling Sequential File Processing

Posted on 2011-09-26
3
180 Views
Last Modified: 2012-05-12
If you want to catch 3 types of exceptions, in other words, you will have 3 catch blocks, which one will you type first, the most specific exception? or the most general exception?
0
Comment
Question by:bakerule22
  • 2
3 Comments
 
LVL 47

Expert Comment

by:for_yan
ID: 36644825

You normally catch the most specific excpetion in the most
inner try - catch area
0
 

Author Comment

by:bakerule22
ID: 36646266
ok thanks
0
 
LVL 47

Accepted Solution

by:
for_yan earned 50 total points
ID: 36646859
see example here:
http://today.java.net/pub/a/today/2003/12/04/exceptions.html

File prefsFile = new File(prefsFilename);

try
{
    readPreferences(prefsFile);
}
catch (FileNotFoundException e)
{
    // alert the user that the specified file
    // does not exist
}
catch (EOFException e)
{
    // alert the user that the end of the file
    // was reached
}
catch (ObjectStreamException e)
{
    // alert the user that the file is corrupted
}
catch (IOException e)
{
    // alert the user that some other I/O
    // error occurred
}

Open in new window

0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Weekend adv creator 3 64
How  can  i  resolve  HTTP Status 404 -? 8 58
Java 8 to Java 6 8 32
Java array 10 54
Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

685 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question