domingo
may212017
Gestión de excepciones.
¿Compilaría y ejecutaría el siguiente código? Si no compila, ¿por qué razón? Si ejecuta, ¿cuál sería la salida?
01.
package
pruebasExcepciones;
02.
03.
public
class
Pruebas {
04.
05.
public
static
void
pruebasExcepciones() {
06.
07.
try
{
08.
09.
System.out.println(
" 1) try "
);
10.
lanzaExcepcion();
11.
12.
}
catch
(Exception e) {
13.
14.
System.out.println(
" 2) catch "
);
15.
throw
e;
16.
17.
}
finally
{
18.
System.out.println(
" 3) finnaly "
);
19.
}
20.
21.
}
22.
23.
public
static
void
main(String[] args) {
24.
25.
try
{
26.
pruebasExcepciones();
27.
}
catch
(Exception e) {
28.
// TODO Auto-generated catch block
29.
e.printStackTrace();
30.
}
31.
32.
System.out.println(
" 4) main "
);
33.
34.
}
35.
36.
public
static
void
lanzaExcepcion() {
37.
throw
new
ArrayIndexOutOfBoundsException();
38.
}
39.
40.
}
Reader Comments