Alle Exceptions auf einmal abfangen

bs

Mitglied
Hallo,

ich weiß nicht ob das als Anfängerfrage zählt (?), aber ich poste es jetzt mal hier:

Gibt es eine Möglichkeit, mehrere Exception auf einmal abzufangen?

Java:
try {
    //Code with exception
}catch(Exception1 e){
    //Exception handling
}catch(Exception2 e){
    //Exception handling
}....

Ich habe immer das gleiche Exception Handling:

Java:
//Exception Handling
Exception ne = new Exception();
System.err.println(ExcpUtils.getMessage(e, ne));
return null;

//ExcpUtils
public static String getMessage(Exception exp, Exception newExp){
    String m = exp.getClass()+": "+exp.getMessage()+" ("+newExp.getStackTrace()[0].getFileName()+": "+newExp.getStackTrace()[0].getLineNumber()+")";
    return m;
}

Ist es irgendwie möglich, alle Exceptions auf einmal abzufangen, damit ich das Exception Handling auch nur einmal pro try/catch-Block habe?

Danke!
 
Danke, so einfach kann es sein 🙂 da hätte ich aber auch selber drauf kommen können :/

Ja ist mir vollkommen klar, dass programm ist nur für testzwecke gedacht bzw. das "wirkliche" exception handling kommt erst später...

nochmals danke...
 

Zurück
Oben