java学习之异常之格式

第一个格式:

try{

}catch(){

}

第二个格式:

try{

}catch(){

}finally{

}

第三个格式:

try{

}finally{

}

注意:catch是用于处理异常,如果没有catch就代表异常没有被处理过,如果该异常是检测时异常,那么必须声明。

package com.dreamy.day04;

/**
 * @author dreamy
 *
 */
class Demo04{
    public void method() {
        try {
            throw new Exception();
        }
        /*
        catch(Exception e) {
            try {
                throw e;
            }catch(){
                
            }
        }
        */
        finally {
            //错误没被处理,所以编译出错
            //关闭资源
        }
    }
}
public class ExceptionDemo04 {

    public static void main(String[] args) {
        
    }

}
原文地址:https://www.cnblogs.com/zhaohuan1996/p/8045181.html