/******************************************************************************
Welcome to GDB Online.
GDB online is an online compiler and debugger tool for C, C++, Python, PHP, Ruby,
C#, OCaml, VB, Perl, Swift, Prolog, Javascript, Pascal, COBOL, HTML, CSS, JS
Code, Compile, Run and Debug online from anywhere in world.
*******************************************************************************/
import java.io.*; // Al inicio se producirá una IOexception = cause
class MiException extends Exception {
public MiException(String MiMssage, Throwable cause){super(MiMssage, cause);}
// otros
}
public class ExcepCadena{
public static void main(String[] args){
try{
met1();
}catch (MiException e){
System.out.println(e.getCause().getCause().getMessage()); // Error inicial: IO Exception
System.out.println(e.getCause().getMessage()); // met2: No puedo resolver este problema
System.out.println(e.getMessage()); // met1: No puedo resolver este problema
System.out.println("main: Escalarlo al programador");
}
}
static void met1() throws MiException{
try {
met2();
} catch (MiException e) {
System.out.println(e.getCause().getMessage());
System.out.println(e.getMessage());
String mensaje = "met1: No puedo resolver este problema";
System.out.println(mensaje + "\n");
throw new MiException(mensaje, e);
}
}
static void met2() throws MiException{
try {
// simular un problema; if(true)
if(true) throw new IOException("Error inicial: IO Exception"); // Genera IOException
} catch (IOException e) {
System.out.println(e.getMessage());
// intenta resolver
String miMessage = "met2: No puedo resolver este problema";
System.out.println(miMessage + "\n");
throw new MiException(miMessage, e);
}
}
}