Java-例外の取得と処理(Java ExceptionDemo)
4780 ワード
// !
//package Main;
//
/**
* @SaySomething( ):
* :Java , ,
* , , , ;
* , , 。
* :
* -
* -
* @Attention( ):
* 1、 Java k :try、catch、finally 。
* 2、 :try...catch、try...catch...finally、try...finally 。
* 3、 finally , ,
* 4、 , (toString())
* , , printStackTrace()
* 5、 Exception , , ,
* Exception , ,
* ( )。
* 6、 。
* 7、 throws 。
* 8、 JVM 。
* 9、throws throw :1、throws , , 。
* 2、 , 。
* 10、RuntimeException Exception :RuntimeException Exception 。
* RuntimeException , Exception ,
* RuntimeException NumberException,ClassCasException、NullPointerExca
* 11、 Exception RuntimeException 。
* 12、java , ,
* 。
* 13、 -ea
* @time( ):-2019/05/04
* @role( ):- ( )
*
* @modify( )-:
* -@time:
* -@role:
*/
/*
public class ExceptionDemo {
public static void main(String[] args) {
System.out.println(" !");
try{//
System.out.println(10/0);
}catch(ArithmeticException AE){//
//System.out.println(" , "+AE);
AE.printStackTrace();//
}finally{
System.out.println(" !");
}
System.out.println(" !");
}
}
*/
/*
class ExceptionDemo1{
public static void main(String[] args) {
System.out.println(" !");
try{//
int x = Integer.parseInt(args[0]);
int y = Integer.parseInt(args[1]);
System.out.println(" :"+(x/y));
//
}catch(ArithmeticException AE1){//
AE1.printStackTrace();//
System.out.println("www");
}catch(NumberFormatException NE1){
NE1.printStackTrace();
System.out.println("www");
}catch(Exception E1){// 。
E1.printStackTrace();
System.out.println("www");
}finally{
System.out.println(" !");
}
System.out.println(" !");
}
}
*/
/*
//throws( )
class ExceptionDemo2{
public static int div(int x,int y)throws Exception{
return x/y ;
}
public static void main(String[] args)throws Exception {
System.out.println(" !");
try{
System.out.println(ExceptionDemo2.div(10,0));
}catch(Exception E2){
E2.printStackTrace();
}
System.out.println(" !");
}
}
*/
/*
//throw( )
class ExceptionDemo3{
public static void main(String[] args){
try{
// ,
throw new Exception(" ") ;
}catch(Exception E3){
E3.printStackTrace() ;
}
}
}
*/
/*
//
class CustomException{
public static void main(String[] args)throws Exception {
CustomException2.eat(11);
}
}
//
class CustomException1 extends Exception{
public CustomException1(String args) {
super(args);
}
}
class CustomException2{
public static void eat(int num)throws CustomException1{
if(num>10){
throw new CustomException1(" , !");
}else{
System.out.println(" , ...");
}
}
}
*/
//assert
class AssertDemo{
public static void main(String[] args) throws Exception{
int x=100 ;
// X ( )
assert x==10:"X 10" ;
System.out.println(x);// , -ea
}
}
/*-----------------------------作者:灭世奶神本文链接:https://blog.csdn.net/qq_36823679/article/details/90614390
著作権声明: 本文はブロガーのオリジナルの文章で、転載はソースのリンクを添付してください!
私の論文があなたに役に立つと思ったら、コメントしてください. 合理的で良質な転送も私の創作継続を奨励する原動力になります!---------------------*/