java exception - cse.seu.edu.cncse.seu.edu.cn/personalpage/wyang/chapter 3.pdf · • input abcd :...
TRANSCRIPT
![Page 2: Java Exception - cse.seu.edu.cncse.seu.edu.cn/PersonalPage/wyang/Chapter 3.pdf · • Input abcd : InputMismatchException. What we met is Exceptional Condition ... Exception Idioms](https://reader035.vdocument.in/reader035/viewer/2022070608/5ab61d257f8b9a6e1c8d70a1/html5/thumbnails/2.jpg)
• Last Chapter Review
• A Notion of Exception
• Java Exceptions
• Exception Handling
• How to Use Exception
• User-defined Exceptions
![Page 3: Java Exception - cse.seu.edu.cncse.seu.edu.cn/PersonalPage/wyang/Chapter 3.pdf · • Input abcd : InputMismatchException. What we met is Exceptional Condition ... Exception Idioms](https://reader035.vdocument.in/reader035/viewer/2022070608/5ab61d257f8b9a6e1c8d70a1/html5/thumbnails/3.jpg)
Last Chapter Review
![Page 4: Java Exception - cse.seu.edu.cncse.seu.edu.cn/PersonalPage/wyang/Chapter 3.pdf · • Input abcd : InputMismatchException. What we met is Exceptional Condition ... Exception Idioms](https://reader035.vdocument.in/reader035/viewer/2022070608/5ab61d257f8b9a6e1c8d70a1/html5/thumbnails/4.jpg)
Last Chapter Review
• java.io.*
• File : A Path in a file system
• I/O Manner
• Text-based (char) / Data-based(byte)
• Sequential / Random Access
![Page 5: Java Exception - cse.seu.edu.cncse.seu.edu.cn/PersonalPage/wyang/Chapter 3.pdf · • Input abcd : InputMismatchException. What we met is Exceptional Condition ... Exception Idioms](https://reader035.vdocument.in/reader035/viewer/2022070608/5ab61d257f8b9a6e1c8d70a1/html5/thumbnails/5.jpg)
Last Chapter Review• Data-based IO
• InputStream/OutputStream
• FileInputStream/FileOutputStream
• DataInputStream/DataOutputStream
• Text-based IO
• Reader/Writer
• FileReader/FileWriter
• RandomAccessFile
![Page 6: Java Exception - cse.seu.edu.cncse.seu.edu.cn/PersonalPage/wyang/Chapter 3.pdf · • Input abcd : InputMismatchException. What we met is Exceptional Condition ... Exception Idioms](https://reader035.vdocument.in/reader035/viewer/2022070608/5ab61d257f8b9a6e1c8d70a1/html5/thumbnails/6.jpg)
A Notion of Exception
![Page 7: Java Exception - cse.seu.edu.cncse.seu.edu.cn/PersonalPage/wyang/Chapter 3.pdf · • Input abcd : InputMismatchException. What we met is Exceptional Condition ... Exception Idioms](https://reader035.vdocument.in/reader035/viewer/2022070608/5ab61d257f8b9a6e1c8d70a1/html5/thumbnails/7.jpg)
Remember File Streampublic class IODemo {
public void demo(String filename){File f = new File(filename);try {
FileInputStream fis = new FileInputStream(f);int b = fis.read();fis.close();
} catch (IOException e){System.out.println(e);
}}
}
![Page 8: Java Exception - cse.seu.edu.cncse.seu.edu.cn/PersonalPage/wyang/Chapter 3.pdf · • Input abcd : InputMismatchException. What we met is Exceptional Condition ... Exception Idioms](https://reader035.vdocument.in/reader035/viewer/2022070608/5ab61d257f8b9a6e1c8d70a1/html5/thumbnails/8.jpg)
Remember File Stream
• filename object is not initialized
• File Exist : ?
• File Not Exist : ?
• File is a Directory : ?
• File has no Content
![Page 9: Java Exception - cse.seu.edu.cncse.seu.edu.cn/PersonalPage/wyang/Chapter 3.pdf · • Input abcd : InputMismatchException. What we met is Exceptional Condition ... Exception Idioms](https://reader035.vdocument.in/reader035/viewer/2022070608/5ab61d257f8b9a6e1c8d70a1/html5/thumbnails/9.jpg)
Remember File Stream• filename object is not initialized:
java.lang.NullPointerException
• File Not Exist : java.io.FileNotFoundException: FileNotExist.txt (No such file or directory)
• File is a Directory : java.io.FileNotFoundException: /usr (/usr Is a directory))
• File have no content: return -1
• File is exist and have content: OK
![Page 10: Java Exception - cse.seu.edu.cncse.seu.edu.cn/PersonalPage/wyang/Chapter 3.pdf · • Input abcd : InputMismatchException. What we met is Exceptional Condition ... Exception Idioms](https://reader035.vdocument.in/reader035/viewer/2022070608/5ab61d257f8b9a6e1c8d70a1/html5/thumbnails/10.jpg)
Another Example public class ATMDemo {
static Account[] users = new Account[20];
public Account login(){System.out.println("Please input Account Name: ");Scanner s = new Scanner(System.in);int inputID = Integer.parseInt(s.nextLine());Account account = users[inputID];System.out.println("User " + inputID + "login");return account;
}}
![Page 11: Java Exception - cse.seu.edu.cncse.seu.edu.cn/PersonalPage/wyang/Chapter 3.pdf · • Input abcd : InputMismatchException. What we met is Exceptional Condition ... Exception Idioms](https://reader035.vdocument.in/reader035/viewer/2022070608/5ab61d257f8b9a6e1c8d70a1/html5/thumbnails/11.jpg)
Another Example• Input 0~19 ?
• Input -1 ?
• Input 20 ?
• Input abcd ?
![Page 12: Java Exception - cse.seu.edu.cncse.seu.edu.cn/PersonalPage/wyang/Chapter 3.pdf · • Input abcd : InputMismatchException. What we met is Exceptional Condition ... Exception Idioms](https://reader035.vdocument.in/reader035/viewer/2022070608/5ab61d257f8b9a6e1c8d70a1/html5/thumbnails/12.jpg)
Another Example• Input 0~19 : NullPointerException
• Input -1 : ArrayIndexOutOfBoundsException
• Input 20 : ArrayIndexOutOfBoundsException
• Input abcd : InputMismatchException
![Page 13: Java Exception - cse.seu.edu.cncse.seu.edu.cn/PersonalPage/wyang/Chapter 3.pdf · • Input abcd : InputMismatchException. What we met is Exceptional Condition ... Exception Idioms](https://reader035.vdocument.in/reader035/viewer/2022070608/5ab61d257f8b9a6e1c8d70a1/html5/thumbnails/13.jpg)
What we met is Exceptional Condition
• Exceptional Condition
• No input or output file
• Visit a Null reference
• Access array out of bound
• A Sound Program Should
• Declare the possible exceptional condition
• Handle the exceptions at right time and in right place
![Page 14: Java Exception - cse.seu.edu.cncse.seu.edu.cn/PersonalPage/wyang/Chapter 3.pdf · • Input abcd : InputMismatchException. What we met is Exceptional Condition ... Exception Idioms](https://reader035.vdocument.in/reader035/viewer/2022070608/5ab61d257f8b9a6e1c8d70a1/html5/thumbnails/14.jpg)
Exception Case
• Normal Condition
• Not Normal, But you know it may happen, and you allow it happen
• Not Normal, and you don’t allow it happen
![Page 15: Java Exception - cse.seu.edu.cncse.seu.edu.cn/PersonalPage/wyang/Chapter 3.pdf · • Input abcd : InputMismatchException. What we met is Exceptional Condition ... Exception Idioms](https://reader035.vdocument.in/reader035/viewer/2022070608/5ab61d257f8b9a6e1c8d70a1/html5/thumbnails/15.jpg)
Too Much Code in main
logic
public static void demo(String filename){if (filename==null){
System.out.println("filename is null");return;
}File f = new File(filename);try {
if (!f.exists()){System.out.println("No Such File or Directory");return;
} if(f.isDirectory()){
System.out.println(filename + " is a Directory");return;
}FileInputStream fis = new FileInputStream(f);int b = fis.read();while(b != -1){
System.out.println(b);b = fis.read();
}fis.close();
} catch (IOException e){System.out.println(e);
}}
![Page 16: Java Exception - cse.seu.edu.cncse.seu.edu.cn/PersonalPage/wyang/Chapter 3.pdf · • Input abcd : InputMismatchException. What we met is Exceptional Condition ... Exception Idioms](https://reader035.vdocument.in/reader035/viewer/2022070608/5ab61d257f8b9a6e1c8d70a1/html5/thumbnails/16.jpg)
Java Exception
• Java Exception
• Offering a clear grammar for handling program correctness
• Balancing between Clarity and Correctness
![Page 17: Java Exception - cse.seu.edu.cncse.seu.edu.cn/PersonalPage/wyang/Chapter 3.pdf · • Input abcd : InputMismatchException. What we met is Exceptional Condition ... Exception Idioms](https://reader035.vdocument.in/reader035/viewer/2022070608/5ab61d257f8b9a6e1c8d70a1/html5/thumbnails/17.jpg)
Java Exception
![Page 18: Java Exception - cse.seu.edu.cncse.seu.edu.cn/PersonalPage/wyang/Chapter 3.pdf · • Input abcd : InputMismatchException. What we met is Exceptional Condition ... Exception Idioms](https://reader035.vdocument.in/reader035/viewer/2022070608/5ab61d257f8b9a6e1c8d70a1/html5/thumbnails/18.jpg)
What is Java Exception• An Object
• A tree of classes
• Key word:
• Throw
• Exception
• Try/Catch/Finally
![Page 19: Java Exception - cse.seu.edu.cncse.seu.edu.cn/PersonalPage/wyang/Chapter 3.pdf · • Input abcd : InputMismatchException. What we met is Exceptional Condition ... Exception Idioms](https://reader035.vdocument.in/reader035/viewer/2022070608/5ab61d257f8b9a6e1c8d70a1/html5/thumbnails/19.jpg)
Java Exceptions
![Page 20: Java Exception - cse.seu.edu.cncse.seu.edu.cn/PersonalPage/wyang/Chapter 3.pdf · • Input abcd : InputMismatchException. What we met is Exceptional Condition ... Exception Idioms](https://reader035.vdocument.in/reader035/viewer/2022070608/5ab61d257f8b9a6e1c8d70a1/html5/thumbnails/20.jpg)
public void demo(String filename){File file = new File(filename);try {
FileInputStream fis = new FileInputStream(f);int b = fis.read();fis.close();
} catch (IOException e){System.out.println(e);
}}
Example
IOException e = new FileNotFindException
(filename);throw e;
![Page 21: Java Exception - cse.seu.edu.cncse.seu.edu.cn/PersonalPage/wyang/Chapter 3.pdf · • Input abcd : InputMismatchException. What we met is Exceptional Condition ... Exception Idioms](https://reader035.vdocument.in/reader035/viewer/2022070608/5ab61d257f8b9a6e1c8d70a1/html5/thumbnails/21.jpg)
public void demo(String filename){File file = new File(filename);FileInputStream fis = null;try {
FileInputStream fis = new FileInputStream(f);int b = fis.read();
} catch (IOException e){System.out.println(e);
} finally {try {
if(fis != null){fis.close();}} catch (IOException e){
System.out.println(e);}
}}
Examples Con’t
jump into catch
jump into finallyjump into
finally
File not ExistFile Exist
![Page 22: Java Exception - cse.seu.edu.cncse.seu.edu.cn/PersonalPage/wyang/Chapter 3.pdf · • Input abcd : InputMismatchException. What we met is Exceptional Condition ... Exception Idioms](https://reader035.vdocument.in/reader035/viewer/2022070608/5ab61d257f8b9a6e1c8d70a1/html5/thumbnails/22.jpg)
Exception Flow• try, catch and finally
• try is used to monitor method invocation
• catch is used to catch thrown exceptions
• finally is used for execute essential code – whether there are exceptions or not
• Multiple catch clause
• At least one catch or finally clause
![Page 23: Java Exception - cse.seu.edu.cncse.seu.edu.cn/PersonalPage/wyang/Chapter 3.pdf · • Input abcd : InputMismatchException. What we met is Exceptional Condition ... Exception Idioms](https://reader035.vdocument.in/reader035/viewer/2022070608/5ab61d257f8b9a6e1c8d70a1/html5/thumbnails/23.jpg)
Examples : Multi Catchpublic void test(File file){
try{checkFile(file);
} catch (IOException e){System.out.println(e.getMessage());
} catch (IllegalArgumentException e){System.out.println("Please Provide a File");
} catch (Exception e){System.out.println("Other Exception occurs");
} finally {delete(file);
}}
![Page 24: Java Exception - cse.seu.edu.cncse.seu.edu.cn/PersonalPage/wyang/Chapter 3.pdf · • Input abcd : InputMismatchException. What we met is Exceptional Condition ... Exception Idioms](https://reader035.vdocument.in/reader035/viewer/2022070608/5ab61d257f8b9a6e1c8d70a1/html5/thumbnails/24.jpg)
Declare Exception• throw and throws – Declare Possible Exceptions
• throw throws exceptions in method body
• throws defines Exception Specificationpublic void checkFile(File file) throws IOException,IllegalArgumentException{
if(!file.exists()){throw new IOException("File Don't exist!");
} else if(file.isDirectory()){throw new IllegalArgumentException("File is a Directory");
} else {……throw new Exception("Blabla");
}}
![Page 25: Java Exception - cse.seu.edu.cncse.seu.edu.cn/PersonalPage/wyang/Chapter 3.pdf · • Input abcd : InputMismatchException. What we met is Exceptional Condition ... Exception Idioms](https://reader035.vdocument.in/reader035/viewer/2022070608/5ab61d257f8b9a6e1c8d70a1/html5/thumbnails/25.jpg)
‘s Family
• ‘s family
• extends
• implements
• throws
• all with declaration
![Page 26: Java Exception - cse.seu.edu.cncse.seu.edu.cn/PersonalPage/wyang/Chapter 3.pdf · • Input abcd : InputMismatchException. What we met is Exceptional Condition ... Exception Idioms](https://reader035.vdocument.in/reader035/viewer/2022070608/5ab61d257f8b9a6e1c8d70a1/html5/thumbnails/26.jpg)
Exception in Overriding• Exception in Overriding
• Which is allowed?public class A {
public void test() throws IOException, IllegalArgumentException{}
}public class B extends A{
public void test() throws IOException{}
}public class C extends A{
public void test() throws Exception{}
}
![Page 27: Java Exception - cse.seu.edu.cncse.seu.edu.cn/PersonalPage/wyang/Chapter 3.pdf · • Input abcd : InputMismatchException. What we met is Exceptional Condition ... Exception Idioms](https://reader035.vdocument.in/reader035/viewer/2022070608/5ab61d257f8b9a6e1c8d70a1/html5/thumbnails/27.jpg)
public class A {public void test() throws IOException, IllegalArgumentException{}
}public class B extends A{
public void test() throws IOException{}
}public class C extends A{
public void test() throws Exception{}
}
Wrong
Right
![Page 28: Java Exception - cse.seu.edu.cncse.seu.edu.cn/PersonalPage/wyang/Chapter 3.pdf · • Input abcd : InputMismatchException. What we met is Exceptional Condition ... Exception Idioms](https://reader035.vdocument.in/reader035/viewer/2022070608/5ab61d257f8b9a6e1c8d70a1/html5/thumbnails/28.jpg)
Examples• Exception in Overriding
• Which is allowed?
• Remember the compatibility
• the return type is reduced
• the access control is enlarged
• the exception type is reduced
![Page 29: Java Exception - cse.seu.edu.cncse.seu.edu.cn/PersonalPage/wyang/Chapter 3.pdf · • Input abcd : InputMismatchException. What we met is Exceptional Condition ... Exception Idioms](https://reader035.vdocument.in/reader035/viewer/2022070608/5ab61d257f8b9a6e1c8d70a1/html5/thumbnails/29.jpg)
Exception Handling
![Page 30: Java Exception - cse.seu.edu.cncse.seu.edu.cn/PersonalPage/wyang/Chapter 3.pdf · • Input abcd : InputMismatchException. What we met is Exceptional Condition ... Exception Idioms](https://reader035.vdocument.in/reader035/viewer/2022070608/5ab61d257f8b9a6e1c8d70a1/html5/thumbnails/30.jpg)
Catch and Handling of Exceptionspre();
try {
// actions;
} catch (ExceptionType1 e) {
} catch (ExceptionType2 e) {
} finally {
post();
}
![Page 31: Java Exception - cse.seu.edu.cncse.seu.edu.cn/PersonalPage/wyang/Chapter 3.pdf · • Input abcd : InputMismatchException. What we met is Exceptional Condition ... Exception Idioms](https://reader035.vdocument.in/reader035/viewer/2022070608/5ab61d257f8b9a6e1c8d70a1/html5/thumbnails/31.jpg)
Catch and Handling of ExceptionsObject val = null;
try {
val = pre();
// actions;
} catch (ExceptionType1 e) {
} catch (ExceptionType2 e) {
} finally {
post();
}
![Page 32: Java Exception - cse.seu.edu.cncse.seu.edu.cn/PersonalPage/wyang/Chapter 3.pdf · • Input abcd : InputMismatchException. What we met is Exceptional Condition ... Exception Idioms](https://reader035.vdocument.in/reader035/viewer/2022070608/5ab61d257f8b9a6e1c8d70a1/html5/thumbnails/32.jpg)
Rethrow Exceptionspublic void function () throws Exception1, Exception2 {
pre();
try {
// actions;
} finally {
post();
}
}
![Page 33: Java Exception - cse.seu.edu.cncse.seu.edu.cn/PersonalPage/wyang/Chapter 3.pdf · • Input abcd : InputMismatchException. What we met is Exceptional Condition ... Exception Idioms](https://reader035.vdocument.in/reader035/viewer/2022070608/5ab61d257f8b9a6e1c8d70a1/html5/thumbnails/33.jpg)
About Return Valuepublic Type function () throws Exception2 {
Type ret = default value // like false or true for boolean,
pre();
try {
// actions;
ret = success value // like true
} catch (Exception1 e){
ret = failure value // like false
} finally {
post();
return ret;
}
}
![Page 34: Java Exception - cse.seu.edu.cncse.seu.edu.cn/PersonalPage/wyang/Chapter 3.pdf · • Input abcd : InputMismatchException. What we met is Exceptional Condition ... Exception Idioms](https://reader035.vdocument.in/reader035/viewer/2022070608/5ab61d257f8b9a6e1c8d70a1/html5/thumbnails/34.jpg)
Define Exception• Message
• new Exception(String message)
• getMessage()
• Cause
• initCause()
• new Exception(Exception cause)
• getCause()
• StackTrace
• printStackTrace()
![Page 35: Java Exception - cse.seu.edu.cncse.seu.edu.cn/PersonalPage/wyang/Chapter 3.pdf · • Input abcd : InputMismatchException. What we met is Exceptional Condition ... Exception Idioms](https://reader035.vdocument.in/reader035/viewer/2022070608/5ab61d257f8b9a6e1c8d70a1/html5/thumbnails/35.jpg)
User Defined Exceptionpublic class BadObjectException extends Exception {
private Object badObj;public BadObjectException(Object object, String msg){
super(msg);this.badObj = object;
}
public Object getBadObj(){return badObj;
}}
![Page 36: Java Exception - cse.seu.edu.cncse.seu.edu.cn/PersonalPage/wyang/Chapter 3.pdf · • Input abcd : InputMismatchException. What we met is Exceptional Condition ... Exception Idioms](https://reader035.vdocument.in/reader035/viewer/2022070608/5ab61d257f8b9a6e1c8d70a1/html5/thumbnails/36.jpg)
Runtime Exception
• Throwable Exceptions in Normal Run-time
• Difference: DO NOT HAVE TO Declare
• Example:
• NullPointerException
• ArithmeticException
• BufferOverflowException
RuntimeException is the superclass of those exceptions that can be thrown during the normal operation of the Java Virtual Machine.
It’s HARM to run program continuously
![Page 37: Java Exception - cse.seu.edu.cncse.seu.edu.cn/PersonalPage/wyang/Chapter 3.pdf · • Input abcd : InputMismatchException. What we met is Exceptional Condition ... Exception Idioms](https://reader035.vdocument.in/reader035/viewer/2022070608/5ab61d257f8b9a6e1c8d70a1/html5/thumbnails/37.jpg)
How to Use Exception
![Page 38: Java Exception - cse.seu.edu.cncse.seu.edu.cn/PersonalPage/wyang/Chapter 3.pdf · • Input abcd : InputMismatchException. What we met is Exceptional Condition ... Exception Idioms](https://reader035.vdocument.in/reader035/viewer/2022070608/5ab61d257f8b9a6e1c8d70a1/html5/thumbnails/38.jpg)
Exception Idioms• Use exceptions only for exceptional conditions
• Use checked exceptions for recoverable conditions and runtime exceptions for programming errors
• Avoid unnecessary use of checked exceptions
• Favor the use of standard Exceptions
• Throw exceptions appropriate to the abstraction
• Document all exceptions thrown by each method
• Include failure-capture information in detail messages
• Strive for failure atomicity
• Don’t ignore exceptions
![Page 39: Java Exception - cse.seu.edu.cncse.seu.edu.cn/PersonalPage/wyang/Chapter 3.pdf · • Input abcd : InputMismatchException. What we met is Exceptional Condition ... Exception Idioms](https://reader035.vdocument.in/reader035/viewer/2022070608/5ab61d257f8b9a6e1c8d70a1/html5/thumbnails/39.jpg)
Avoid unnecessary use of checked exceptions
• Checked Exception : the program maybe recovered, not in normal control logic
• Runtime Exception: the program has bugs and should be avoid
• Error: the vm/program have fatal errors, the program should be terminated immediately
• Normal Condition: should be in normal control logic
![Page 40: Java Exception - cse.seu.edu.cncse.seu.edu.cn/PersonalPage/wyang/Chapter 3.pdf · • Input abcd : InputMismatchException. What we met is Exceptional Condition ... Exception Idioms](https://reader035.vdocument.in/reader035/viewer/2022070608/5ab61d257f8b9a6e1c8d70a1/html5/thumbnails/40.jpg)
Exception Conditions• Exceptional Condition VS. Normal Problems
• End of file is a normal problem
• Normal problem does not lead to program halt
• Exceptional conditions lead to program halt
• Exceptional Condition VS. Error Condition
• JVM crash is an error condition
• Error conditions cannot be handled by program
• Exceptional conditions can and should be handled by program
![Page 41: Java Exception - cse.seu.edu.cncse.seu.edu.cn/PersonalPage/wyang/Chapter 3.pdf · • Input abcd : InputMismatchException. What we met is Exceptional Condition ... Exception Idioms](https://reader035.vdocument.in/reader035/viewer/2022070608/5ab61d257f8b9a6e1c8d70a1/html5/thumbnails/41.jpg)
Wrong Exception Usagepublic void demo(String filename){
File file = new File(filename);FileInputStream fis = null;try {
FileInputStream fis = new FileInputStream(f);int b = fis.read();while(true) {
b = fis.read();}
} catch (EOFException e){System.out.println(e);
} finally {try {
if(fis != null){fis.close();}} catch (IOException e){
System.out.println(e);}
}}
Wrong Usage
![Page 42: Java Exception - cse.seu.edu.cncse.seu.edu.cn/PersonalPage/wyang/Chapter 3.pdf · • Input abcd : InputMismatchException. What we met is Exceptional Condition ... Exception Idioms](https://reader035.vdocument.in/reader035/viewer/2022070608/5ab61d257f8b9a6e1c8d70a1/html5/thumbnails/42.jpg)
Favor the use of standard Exceptions
• IllegalArgumentException
• IllegalStateException
• UnsupportOperationException
• ConcurrentModificationException
![Page 43: Java Exception - cse.seu.edu.cncse.seu.edu.cn/PersonalPage/wyang/Chapter 3.pdf · • Input abcd : InputMismatchException. What we met is Exceptional Condition ... Exception Idioms](https://reader035.vdocument.in/reader035/viewer/2022070608/5ab61d257f8b9a6e1c8d70a1/html5/thumbnails/43.jpg)
Throw exceptions appropriate to the abstraction
• Exception Message should reflect the semantic of the method
• Exception Chain Handling
public void deposit( int id, int moneyVal){users[id].money += moneyVal;
}ArrayIndexOutofBound
public void menu (){……deposit(-1,200);……
}
IllegalArgument
![Page 44: Java Exception - cse.seu.edu.cncse.seu.edu.cn/PersonalPage/wyang/Chapter 3.pdf · • Input abcd : InputMismatchException. What we met is Exceptional Condition ... Exception Idioms](https://reader035.vdocument.in/reader035/viewer/2022070608/5ab61d257f8b9a6e1c8d70a1/html5/thumbnails/44.jpg)
Strive for failure atomicity
• Object state should not change when Exceptions occur
• But How?
• Change the process logic
• verify the params before invoke the method
• recovery code
• backup data
public void AddUser( Account account){ATMDemo.userCount += 1;users[ATMDemo.userCount] = account;
}
![Page 45: Java Exception - cse.seu.edu.cncse.seu.edu.cn/PersonalPage/wyang/Chapter 3.pdf · • Input abcd : InputMismatchException. What we met is Exceptional Condition ... Exception Idioms](https://reader035.vdocument.in/reader035/viewer/2022070608/5ab61d257f8b9a6e1c8d70a1/html5/thumbnails/45.jpg)
Self-Study
• Assert
• Exception Chaining