R病 f Understanding Java Exceptions 6 口这部分使用 Manchester University, Kung- Kiu lau CS3101的 PPT SLides nstitute of Computer Software 2021/2/9 Nanjing University
Understanding Java Exceptions 这部分使用Manchester University, Kung-Kiu Lau, CS3101 的PPT Slides 2021/2/9 Institute of Computer Software Nanjing University 6
What are EXceptions? Manyexceptional things can happen during the running of a program, e.g User mis-types input checked Web page not available File not found Array index out of bounds unchecked Method called on a null object Divide by zero Out of memory sys errors Bug in the actual language implementation EXceptions are unexpected conditions in programs
7 What are Exceptions? Many “exceptional” things can happen during the running of a program, e.g.: • Bug in the actual language implementation • User mis-types input • Web page not available • File not found • Divide by zero • Array index out of bounds • Method called on a null object • Out of memory Exceptions are unexpected conditions in programs. checked unchecked sys errors
We can distinguish 3 categories checked exceptions- Problems to do with the program's interaction with"the world unchecked exceptions The world is unpredictable, so we itself(i.e. violations of the d would expect these things to system errors- Problems happen in proa ation code, and so nee These are outside our contron These should be removed by testing and not occur in production code The World Checked EXceptions Unchecked Program Exceptions System System Errors 8
8 We can distinguish 3 categories: • checked exceptions — Problems to do with the program's interaction with “the world”. • unchecked exceptions — Problems within the program itself (i.e. violations of the contract, or bugs). • system errors — Problems with the underlying system. These are outside our control. The world is unpredictable, so we would expect these things to happen in production code, and so need to handle them. These should be removed by testing, and not occur in production code. Unchecked Exceptions System Errors Program System The World Checked Exceptions
Checked vs Unchecked Exceptions an important distinction which the Java it's normal to let these pn class hijerawe woe normay theck for just crash the program h a rather conthese, and deal with them so we can debug it when they occur The World Checked Exceptions Unchecked Program EXceptions System System Errors Exception handling is the business of handling these things appropriately 9
9 Checked vs Unchecked Exceptions Unchecked Exceptions System Errors Program System The World Checked Exceptions an important distinction, which the Java Exception class hierarchy does make, but in a rather confusing way we would normally check for these, and deal with them when they occur. it's normal to let these just crash the program so we can debug it. Exception handling is the business of handling these things appropriately
EXception Hierarchy in Java Throwable Exception RuntimeExcep七ion Excep The Run七 imeException World Checked RuntimeException EXceptions Unchecked Program E卫。 EXceptions System System Errors 10
10 Exception Hierarchy in Java Throwable Exception RuntimeException Error . . . Unchecked Exceptions System Errors Program System The World Checked Exceptions Error RuntimeException Exception − RuntimeException