Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

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.

Last change: , commit: 08d1c57