Llençant excepcions

Checked

Es pot llençar, i cal especificar-ho.

public void metode() throws SomeException { // ... throw new SomeException("some text"); }

Unchecked

No cal especificar-la:

public void metode() { // ... throw new SomeException("some text"); }

Rethrowing

Tornem a llençar l'excepció gestionada:

try { // ... } catch (SomeException e) { throw e; }

Wrapping

Fem un embolcall:

try { // ... } catch (SomeException e) { throw new SomeOtherException("una explicació", e); }

Herència

Quan sobreescribim un mètode, podem fer que la subclasse tingui una signatura menys arriscada, o sigui, sense el throws.

Veure la interpretació de les excepcions.