1 class-da try{} blogu catch ve finally olmadan yazilsa xeta verecek.Eger try ve catch bloglari arasina her hansi 1 kod setiri yazilsa xeta verecek.meselen:
try{
}
System.out.print("hello");
catch(Exception e){
}
Exceptionlar java.langg.Exceptionun subclasslaridirlar.Throwable Exceptionun super classidir,Object ise hamisinin super class-dir.
Throwable 2 yere bolunur:
- Error
- Exception
Exceptionlar 2 yere bolunr:
- Checked exception
- Unchecked exception veya Runtime Exception.
- ClassBotFoundException
- IOException buda 2 yere bolunur: 1) EOFException ve 2)FileNotFoundException
- ParseException
- ArithmeticException
- ClassCastException
- IllegalArgumentException buda 2 yere bolunur:1) IllegalThreadStateException ve 2) NumberFormatException
- IndexOutOfBoundsException buda 2 yere bolunur:1)StringIndexBoundsException ve 2) ArrayIndexOutOfBoundsException
- NegativeArraySizeException
- NullPointerException
- SecurityException
try{ }
catch(IOException e){}
catch(FileNotFoundException ex) { } // burada xeta verecek.Cunki 1ci subi sonra superi gelmelidi.balacadan boyuye.
Eger 1 metodun basinda throws yazilibsa bu o demekdirki bu metodu kim istifade etse try ve catch atmalidir.
void doMore() throws IOException { ... }
bu kodu istifade edende mutleq try ve catch atilmalidir.
RuntimeException ,Error ve onlarin butun sublari unchecked exceptiondurlar. ve onlari mueyyen etmek veya handle etmek olmur.Yerde qalan diger exceptionlar ise checked olurlar ve onlar java.lang.RuntimeException-dan toremirler.Checked Exceptionlar kodda istenilen yerde tutula bilerler.Eger 1 checked exception atan metod cagirilirsa ve tutulmursa o zaman kod compile olmayacaq.
Exceptionlar JVM (yeni runtime) ve Programmatic ( yeni compiler) exception olmaqla 2 yere bolunurler.
JVM exceptionlar JVM terefinden atilir.
Programmatic Exceptionlar ise API programmerler veya applicationlar terefinden atilir.
Programmatical exceptionlar asagidakilardir:
- AssertionError
- NumberFormatExcepption
- IllegalArgumentException
- IllegalStateException
Hiç yorum yok:
Yorum Gönder