Je n'ai pas essayé cela, donc je ne sais pas si la JVM restreindrait quelque chose comme ça, mais peut-être pourriez-vous compiler du code qui lance ChuckNorrisException, mais au moment de l'exécution, fournissez une définition de classe ChuckNorrisExceptionqui ne prolonge pas Throwable .
MISE À JOUR:
Ça ne marche pas. Il génère une erreur de vérificateur:
Exception in thread "main" java.lang.VerifyError: (class: TestThrow, method: ma\
in signature: ([Ljava/lang/String;)V) Can only throw Throwable objects
Could not find the main class: TestThrow.  Program will exit.
MISE À JOUR 2:
En fait, vous pouvez le faire fonctionner si vous désactivez le vérificateur de code d'octet! ( -Xverify:none)
MISE À JOUR 3:
Pour ceux qui suivent de chez eux, voici le script complet:
Créez les classes suivantes:
public class ChuckNorrisException
    extends RuntimeException // <- Comment out this line on second compilation
{
    public ChuckNorrisException() { }
}
public class TestVillain {
    public static void main(String[] args) {
        try {
            throw new ChuckNorrisException();
        }
        catch(Throwable t) {
            System.out.println("Gotcha!");
        }
        finally {
            System.out.println("The end.");
        }
    }
}
Compiler les classes:
javac -cp . TestVillain.java ChuckNorrisException.java
Courir:
java -cp . TestVillain
Gotcha!
The end.
Commentez "étend RuntimeException" et recompilez ChuckNorrisException.javauniquement :
javac -cp . ChuckNorrisException.java
Courir:
java -cp . TestVillain
Exception in thread "main" java.lang.VerifyError: (class: TestVillain, method: main signature: ([Ljava/lang/String;)V) Can only throw Throwable objects
Could not find the main class: TestVillain.  Program will exit.
Exécuter sans vérification:
java -Xverify:none -cp . TestVillain
The end.
Exception in thread "main"