Solved

Java Exception handling Sequential File Processing

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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
GUI builder for Eclipse? 8 35
Unhandled exception type Exception 18 31
Android development question 2 37
Java: anonymous class 4 19
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 …
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

772 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