Exception Handling in Java1Exception Handling in Java
Exception Handling in Java2Exception Handling in JavaTopics:IntroductionErrors and Error handlingExceptionsTypes of ExceptionsCoding ExceptionsSummary
Exception Handling in Java3IntroductionUsers have high expectations for the code we produce.Users will use our programs in unexpected ways.Due to design errors or coding errors, our programs may fail in unexpected ways during execution
Exception Handling in Java4IntroductionIt is our responsibility to produce quality code that does not fail unexpectedly.Consequently, we must design error handling into our programs.
Exception Handling in Java5Errors and Error HandlingAn Error is any unexpected result obtained from a program during execution.Unhandled errors may manifest themselves as incorrect results or behavior, or as abnormal program termination.Errors should be handled by the programmer, to prevent them from reaching the user.
Exception Handling in Java6Errors and Error HandlingSome typical causes of errors:Memory errors (i.e. memory incorrectly allocated, memory leaks, “null pointer”)File system errors (i.e. disk is full, disk has been removed)Network errors (i.e. network is down, URL does not exist)Calculation errors (i.e. divide by 0)
Exception Handling in Java7Errors and Error HandlingMore typical causes of errors:Array errors (i.e. accessing element –1)Conversion errors (i.e. convert ‘q’ to a number)Can you think of some others?
Exception Handling in Java8Errors and Error HandlingTraditional Error Handling1. Every method returns a value (flag) indicating either success, failure, or some error condition. The calling method checks the return flag and takes appropriate action.