工作时,一直对try块中throw的异常对象,在catch中如何处理此异常,以及trycatchfinally完毕,程序是否就此停止还是继续运行很迷惑,于是参考网上的资料,自己写了些demo,去慢慢探索. 例1. public static void main(String[] args) { int i = 7; int j = 0; try { if (j == 0) throw new ArithmeticException(); System.out.println("打印计算结果i/j…
try { int i = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("in the 'try'"); } catch { Console.WriteLine("in the 'catch'"); } finally { Console.WriteLine("in the 'finally'"); } Console.WriteLine("After the 'fina…
当我们完成一个程序时,如果没有异常捕获的话,用户使用时会出现许多bug.而加入异常捕获之后便会提醒用户使用时避免产生不必要的错误.具体操作实现如下: 首先创造一个MyException类,继承自Exception类,在MyException的方法中调用父类的方法,返回错误的提示信息. package classTest; public class MyException extends Exception { private static final long serialVersionUID…