• Welcome to the world's largest Chinese hacker forum

    Welcome to the world's largest Chinese hacker forum, our forum registration is open! You can now register for technical communication with us, this is a free and open to the world of the BBS, we founded the purpose for the study of network security, please don't release business of black/grey, or on the BBS posts, to seek help hacker if violations, we will permanently frozen your IP and account, thank you for your cooperation. Hacker attack and defense cracking or network Security

    business please click here: Creation Security  From CNHACKTEAM

Recommended Posts

异常处理机制

抛出异常

捕获异常

异常处理五个关键字

尝试、抓住、最后、扔、扔

Test.java

包异常

公共类测试{

公共静态void main(String[] args) {

尝试{

新测试()。test(1,0);

} catch(异常e) {

抛出新的运行时异常(e);

}最后{//使用试着接住后,程序会继续执行

}

}

//假设这个方法中,处理不了这个异常,方法上抛出异常

公共无效测试(int a,int b)抛出算术异常{

if (b==0){//throw vs throws

抛出新的算术异常();//主动抛出异常,一般在方法中使用

}

//系统。出去。println(a/b);

}

}

/*

int a=1;

int b=0;

//假设要捕获多个异常:从小到大捕获!

尝试{//尝试监督区域

if (b==0){//throw vs throws

抛出新的算术异常();//主动抛出异常

}

系统。出去。println(a/b);

}catch(错误e){//catch(想要捕获的异常类型!)捕获异常

系统。出去。println(“错误”);

}catch(异常e){

系统。出去。println("异常");

}catch (Throwable t){

系统。出去。println(' Throwable ');

}最后{//处理善后工作

系统。出去。println('最终');

}

//最后可以不要最后,假设木卫一,资源,关闭!

*/

Test2.java

包异常

公共类测试2 {

公共静态void main(String[] args) {

int a=1;

int b=0;

//Ctrl Alt T

尝试{

系统。出去。println(a/b);

} catch(异常e) {

抛出新的运行时异常(e);//抛出异常,e.printStackTrace()打印错误的栈信息

}最后{

}

}

}

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now