Eine generische Ausnahme in Java abfangen?

Post a reply

Smilies
:) :( :oops: :chelo: :roll: :wink: :muza: :sorry: :angel: :read: *x) :clever:
View more smilies

BBCode is ON
[img] is ON
[flash] is OFF
[url] is ON
Smilies are ON

Topic review
   

Expand view Topic review: Eine generische Ausnahme in Java abfangen?

by Anonymous » 23 Dec 2024, 17:55

Wir verwenden JUnit 3 bei der Arbeit und es gibt keine ExpectedException-Annotation. Ich wollte unserem Code ein Dienstprogramm hinzufügen, um Folgendes zu umschließen:

try {
someCode();
fail("some error message");
} catch (SomeSpecificExceptionType ex) {
}


Also habe ich Folgendes versucht:

public static class ExpectedExceptionUtility {
public static void checkForExpectedException(String message, ExpectedExceptionBlock block) {
try {
block.exceptionThrowingCode();
fail(message);
} catch (T ex) {
}
}
}


Allerdings kann Java meiner Meinung nach keine generischen Ausnahmetypen in einem Catch-Block verwenden.

Wie kann ich das tun? So etwas in der Art, um die Java-Einschränkung zu umgehen?

Gibt es eine Möglichkeit zu überprüfen, ob die ex-Variable vom Typ T ist?

Top