Solved

Java Exception handling Sequential File Processing

Posted on 2011-09-26
3
173 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
Comment Utility

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

Author Comment

by:bakerule22
Comment Utility
ok thanks
0
 
LVL 47

Accepted Solution

by:
for_yan earned 50 total points
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

771 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

11 Experts available now in Live!

Get 1:1 Help Now