ジャワの一般的な例外

com.atguigu.java1パッケージ; 

インポートはjava.io.File;
インポートjava.io.FileInputStream;
インポートjava.util.Date;
インポートjava.util.Scanner;

インポートorg.junit.Test;

/ *
*、異常なアーキテクチャ
*
*たjava.lang.Throwable
* | -----でjava.lang.Error:一般的に、処理対象のコードを記述しないでください。
* | -----のjava.lang.Exception:例外処理を行うことができます
* |異常(チェック)------コンパイル時
* | -----のIOException
* | -----にFileNotFoundException
* | ClassNotFoundExceptionが-----
* | ------実行時例外(チェック、はRuntimeException)
* | ----- NullPointerExceptionが
* | -----は、ArrayIndexOutOfBoundsException
* | -----にClassCastException
* | -----はNumberFormatException
* | ----- InputMismatchException
* | -----はArithmeticException
*
*
*
*フェイス質問:一般的な異常は何ですか?示して
* /
publicクラスExceptionTest {

//以下のコンパイル時例外************************************************** ***************** **********
@Test
ます。public void TEST7(){
//ファイル=新しい新しいファイル( "hello.txt")ファイル;
// = FileInputStreamの新しい新しいFISのFileInputStream(ファイル);
//
// int型のデータfis.read =();
//一方(!データ= -1){
// System.out.print((CHAR)データ);
//データfis.read =();
//}
//
// fis.close();

}

// ******************以下是运行时异常************************ ***
//はArithmeticException
@Test
公共ボイドTEST6(){
int型= 10。
int型、B = 0;
System.out.println(/ B)。
}

// InputMismatchException
@Test
公共ボイドTEST5(){
スキャナスキャナ=新しいスキャナ(System.in)。
INTスコア= scanner.nextInt()。
System.out.println(スコア)。

scanner.close();
}

// NumberFormatExceptionが
@Test
公共ボイドTEST4(){

文字列str = "123"。
STR = "ABC";
INT NUM = Integer.parseInt(STR)。



}

// ClassCastExceptionが
@Test
公共ボイドTEST3(){
オブジェクトOBJ =新しいDate();
文字列str =(文字列)OBJ。
}

//例外:IndexOutOfBoundsException
@Test
公共ボイドTEST2(){
//は、ArrayIndexOutOfBoundsException
// INT [] ARR =新しいINT [10]。
//のSystem.out.println(ARR [10])。
// StringIndexOutOfBoundsExceptionを
文字列str = "ABC";
System.out.println(str.charAt(3))。
}

// NullPointerExceptionが
@Test
公共ボイドTEST1(){

// INT [] ARR = NULL;
//のSystem.out.println(ARR [3])。

文字列str = "ABC";
STR = NULL;
System.out.println(str.charAt(0))。

}


}

おすすめ

転載: www.cnblogs.com/wpy188/p/12088921.html