Sie fangen die falsche Ausnahme

Ich bin versucht zu fangen eine bestimmte exception mit MySQL im Java. Aber, es läuft die catch (SQLException ex) anstelle von der, die ich will.

catch (MySQLIntegrityConstraintViolationException ex) {
}
catch (SQLException ex) {
}

Immer folgende Fehlermeldung, ich würde erwarten, dass es laufen die catch (MySQLIntegrityConstraintViolationException ex) Funktion.

11:12:06 AM DAO.UserDAO createUser
SEVERE: null
com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Duplicate entry 'idjaisjddiaij123ij' for key 'udid'

Warum ist es läuft catch (SQLException ex) statt catch (MySQLIntegrityConstraintViolationException ex)?

  • Können Sie hinzufügen, ex.printStackTrace(); in jedem catcha und fügen Sie die Ausnahme?
  • Scheint es in .getCause() durch Zufall?
InformationsquelleAutor Patrick Reck | 2014-02-20
Schreibe einen Kommentar