exception message Exception in thread main java lang
- Slides: 25
ตวอยาง exception message ทระบบเตอนผใช Exception in thread "main" java. lang. Arithmetic. Exception: / by zero at Exception. Demo. main(Exception. Demo. jav a: 5) Exception. Demo : The class name main : The method name Exception. Demo. java : The filename java: 5 : Line number 6
ประเภทของ exceptions (Types of exceptions) ม 2 ประเภท 1)Checked exceptions 2)Unchecked exceptions 7
โครงสรางของ exception (exception hierarchy) 10
การจดการขอผดพลาด (exception handling) ของภาษาจาวา • exception handling ของภาษาจาวามรปแบบการใชงาน ดงน try { <statements>; } catch (Throwable 1 t) { <statements>; } catch (Throwable 2 t) { <statements>; } catch (Throwable 3 t) { <statements>; } 11
พมพ main() call exception activation stack หยดการทำงานของ JVM Exception Method 1 call Exception Method 2 14
ดำเนนการตามทไดดกจบ Exception main() call Exception Method 1 call Method 2 15
ตวอยาง 1. class Array. Out { 2. public static void main(String s []) { 3. System. out. println("Hello " + s[0]); 4. } 5. } Exception in thread "main" java. lang. Array. Index. Out. Of. Bounds. Exception: 0 at Array. Out. main(Array. Out. java: 3) 16
การเพม exception handling 1. class Array. Out { 2. public static void main(String s []) { 3. try 4. { System. out. println("Hello " + s[0]); } 5. catch (Array. Index. Out. Of. Bounds. Exception e) 6. { System. out. println("Please try again" + 7. "with command line"); } 8. } 9. } 17
ตวอยาง 1. class Test. Excep { 2. static void f(){int x = 0; float y = 1/x; } 3. public static void main(String s[]){ 4. try{ 5. f(); 6. }catch (Exception e){ 7. System. out. println("Error divice by 0" + e. get. Message()); } 8. } 9. } 18
ตวอยาง 1. class Throw. Test { 2. static int div(int x, int y){ 3. try { 4. if (y == 0) 5. throw new Exception(); 6. return x/y; 7. } catch (Exception e){return x/y; } 8. } 9. public static void main(String s[ ]){ 10. System. out. println(div(1, 0)); } 11. } 20
ตวอยาง 1. class Method. Throws { 2. static int div(int x, int y) throws Arithmetic. Exception { 3. return x/y; } 4. public static void main(String s[]){ 5. System. out. println(div(1, 0)); 6. } 7. } 22
ตวอยาง 1. import java. lang. * ; 2. import java. io. * ; 3. public class Square { 4. public static void main ( String[] a ) throws IOException { 5. Buffered. Reader stdin = new Buffered. Reader (new Input. Stream. Reader( System. in) ); 6. String in. Data; 7. int num ; 8. System. out. println("Enter an integer: "); 9. in. Data = stdin. read. Line(); 10. num = Integer. parse. Int( in. Data ); // convert in. Data to int 11. System. out. println("The square of " + in. Data + " is " 23 +
1. class Array. Out { 2. public static void main(String s []) { 3. try 4. { System. out. println("Hello " + s[0]); } 5. catch (Array. Index. Out. Of. Bounds. Exception e) 6. { System. out. println("Please try again" + 7. "with command line"); } 8. finally 9. {System. out. println("How are you. "); } 10. } 11. } 25
- Java exception localized message
- Java.lang.util
- Lexicographic order java
- Import java util scanner
- Java lang package
- Java lang math class
- Java.util.io.*
- Types of exception in java
- Java thread states
- Java gui thread
- Esercizi thread java
- Multithreading program in java
- Where t : new()
- Parameterized thread
- Java thread life cycle
- Java import java.io.*
- Java unchecked exceptions list
- Exception vs error in java
- Exception class hierarchy in java
- Exception handling in java
- Exception handling pada java
- Java exception error
- Dasar exception
- Java unchecked exception
- Java unchecked exception
- Catcher in the rye themes