Solved

Is there anyway I can use ‘use case’ for error handling?

Posted on 2004-04-16
7
211 Views
Last Modified: 2010-03-31
Is there anyway I can use ‘use case’ for error handling?

I am sure I have read some where that you can use it for example if error the case1 etc, can this be done in java? can anyone show me any examples if it can be done?
0
Comment
Question by:pigmentarts
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 10846751
Maybe you're thinking about this kind of thing?:

catch(Exception e) {
    if (e instanceof IOException) {
        // do something
    }
    else if (s instanceof ClassCastException) {
        // do something different
    }
}
0
 
LVL 92

Accepted Solution

by:
objects earned 125 total points
ID: 10846763
try
{
    // your code here
}
catch (IOException ex)
{
   // handle IOException here
}
catch (ClassCastException ex)
{
   // handle ClassCastException here
}
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 10846802
You *could* use a case statement but it would be highly artificial and not a good idea
0
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

 
LVL 92

Expert Comment

by:objects
ID: 10846812
0
 
LVL 12

Author Comment

by:pigmentarts
ID: 10846814
it was just i has seen it somewere i wanted to see if it was just in my head or not. thanks.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 10846818
Please explain the reason for accepting that particular answer pigmentarts
0
 
LVL 15

Expert Comment

by:Javatm
ID: 10846833
Hi;

Error handling can delt in many ways like if / else & case statements but the real
way you do that in Java is by using try / catch & finally :

try
{
    if(Your Thing) {
    }
    else {
    }
}
catch (YourException e)
{
   // handle your exception here !
}

Here is a tutorial :
http://java.sun.com/docs/books/tutorial/essential/exceptions/

Hope that helps . . .
Javatm

0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
In this post we will learn different types of Android Layout and some basics of an Android App.
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
Suggested Courses

628 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