异常处理之动手动脑

1.观察代码,了解异常处理机制

import javax.swing.*; class AboutException { public static void main(String[] a) { int i=1, j=0,k; // k=i/j; try { k = i/j; // Causes division-by-zero exception throw new Exception("Hello.Exception!"); } catch ( ArithmeticException e) { System.out.println("被0除. "+ e.getMessage()); } catch (Exception e) { if (e instanceof ArithmeticException) System.out.println("被0除"); else { System.out.println(e.getMessage()); } } finally//用于善后的代码 { JOptionPane.showConfirmDialog(null,"OK"); } } }

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/zgzfwy.html