public class Test { public static void main(String[] args) { try { int a = 1; int b = 0; int c = a/b; } catch(java.lang.Exception e) { StringWriter errors = new StringWriter(); e.printStackTrace(new PrintWriter(errors)); String errorMsg = errors.toString(); System.out.println(errorMsg); } } }
import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.net.MalformedURLException; import java.net.URL; import java.net.URLConnection; import java.text.DecimalFormat; import java.util.ArrayList; import java.util.EventListener; import java.util.List; public class Test { public static void main(String[] args) { int a = 1; int b = 0; int c = 0; try { System.out.println("1"); c = a / b; throw new IOException(); } catch(FileNotFoundException e) { System.out.println("2"); } catch(IOException e) { System.out.println("3"); } catch(Exception e) { System.out.println("4"); c = a / b; } finally { System.out.println("5"); } System.out.println("6"); }