Solved

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

Posted on 2004-04-16
7
205 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
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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
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…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
The viewer will learn how to implement Singleton Design Pattern in Java.

747 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

14 Experts available now in Live!

Get 1:1 Help Now