Solved

Java Exception handling Sequential File Processing

Posted on 2011-09-26
3
175 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

910 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now