Ciao a tutti, stavo studiando le eccezioni in java e in particolare le clausole throws e try-catch-finally. Volevo chiedere, per gestire una eccezione posso usare o la clausola throws in questo modo:
oppure posso anche gestiore l'eccezione tramite i costrutti try-catch-finally:codice:public String prova(int num) throws My_Exception { if( num == 0) throw new My_Exception(); else "OK"; }
questi 2 metodi sono equivalenti o c'è differenza??codice:public String prova(int num) { try { if( num == 0) throw new My_Exception(); } catch ( My_Exception e ) { Syetem.out.println("Illegal number"); } }

Rispondi quotando