Link to home
Start Free TrialLog in
Avatar of pigmentarts
pigmentartsFlag for United Kingdom of Great Britain and Northern Ireland

asked on

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

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?
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

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
    }
}
ASKER CERTIFIED SOLUTION
Avatar of Mick Barry
Mick Barry
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
You *could* use a case statement but it would be highly artificial and not a good idea
Avatar of pigmentarts

ASKER

it was just i has seen it somewere i wanted to see if it was just in my head or not. thanks.
Please explain the reason for accepting that particular answer pigmentarts
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