Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2004-04-16
7
Medium Priority
?
213 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 500 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

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

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
Suggested Courses

916 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