- public class Finally_Return
- {
- /**
- * @param args the command line arguments
- */
- public static void main(String[] args)
- {
- new Demo().method();
- System.out.println("main over");
- }
-
- }
- class Demo
- {
- public void show(int x) throws Exception
- {
- if (x < 0)
- {
- throw new Exception("小于零");
- }
- else
- {
- throw new Exception("大于等于零");
- }
- }
-
- public void method()
- {
- try
- {
- show(1);
- return;
- }
- catch (Exception e)
- {
- System.out.println("异常被捕获");
- }
- finally
- {
- System.out.println("总会被执行");
- }
- System.out.println("method() over");
- }
- }
复制代码
结论:show(1)出现异常的时候程序就会跳转到catch 中,不会执行下面的语句。
|
|