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

Excepcions pròpies

Habitualment, tenim diverses signatures per crear un objecte d’excepció. Tot i que els paràmetres són lliures (podem afegir els que ens ajudin a interpretar el nostre error particular), dos sovintegen:

  • el missatge d’error, un String.
  • una excepció, la causa. Permet enllaçar excepcions amb les seves causes (wrapping).

Per exemple, una excepció checked estenent Exception:

public class SomeException extends Exception {    
    public SomeException (String message, Throwable t) {
        super(message, t);
    }
}

Per exemple, una excepció unchecked estenent RuntimeException:

public class SomeException extends RuntimeException {
    public SomeException (String message, Throwable t) {
        super(message, t);
    }
}
Last change: , commit: 8831cf2