en catchant Exception, on catch Exception et toutes ses sous-classes (RuntimeException, IOException, SQLException, etc...)
cf. l'héritage 
try {...} catch(Exception e) {...}
après, si l'on veut s'assurer que l'exception est d'un type particulier afin de faire un traitement spécial, on peut utiliser instanceof:
1 2 3 4 5 6 7
|
Class<? extends Exception> exceptionToCatch = RuntimeException.class;
try {...} catch(Exception e) {
if(e instanceof exceptionToCatch) {
// là on sait que notre exception est ou hérite de "exceptionToCatch"
}
} |
Partager