if ("error de CRC"){
throw new IOException();
}
void f() throws EOFException, FileNotFoundException{
if ( ... )
throw new EOFException();
if ( ... )
throw new EOFException
}
try{
// Operaciones que pueden producir una excepción
}
catch( TipoDeExcepcion ref ){
// Tratamiento de la excepción
}
try{
a.abrirFichero();
a.leeCabecera();
a.actualizaDatos();
}
catch( FileNotFoundException e ){
System.out.println("Error de apertura: " + e.message());
}
catch( IOException e ){
System.out.println("Error de E/S: " + e.message());
}
void f1( int accion ) throws EOFException{
try{
if( accion == 1 )
throw new FileNotFoundException();
else if( accion == 2 )
throw new EOFException();
}
catch( FileNotFoundException e ){
System.out.println( "Error corregido" );
}
System.out.println("Finalización normal de f1");
}
void f2( int accion ){
try{
f1( accion ):
}
catch( EOFException e ){
System.out.println( "Error corregido" );
}
System.out.println("Finalización normal de f2");
}
try{
// Operaciones posibles
}
catch( Exception e ){
// Tratamiento de la excepción
}
finally{
// Operaciones comunes a ambas.
}
try{
// Operaciones posibles
}
catch( Exception e ){
// Tratamiento de la excepción
throw e;
}