Error Handling 

  • So far, in the examples we have discussed, there has been little room for user error. That is, for the most part, if there is an error in the program it is our own fault rather than some unforeseen user blunder such as entering letters into a price field or a URL which does not exist. These types of errors can never be exactly programmed around because it is impossible to handle every weird thing that a user might do. We can handle programmatic errors by simply writing error-free code, but we cannot assure that run-time errors will not break our program. 
  • Thus, run time errors are just as important to deal with as errors in your programming code. In fact, they are often more important since your users will not be able to find the bug and recompile the program like you will be able to do. At run time, it is too late to debug. 
  • In order to handle the exceptional cases in which the user enters data which would cause your program to crash, Java provides a hearty exception handling methodology to catch erroneous input, try several methods to deal with it, and in the worst case, gracefully exit the program. 
  • So how does Java deal with exceptions in the program? 
  • Well specifically, when an error occurs, Java will encapsulate all the information about the error in a special error object. 
  • Thus, rather than choke on the error, the routine which generates the error will look for an event handler object which can deal with the unexpected problem. 
  • The event handler object will look at the error event object and decide what to do from there. 
  • Your job is to facilitate this methodology by creating the logic for the exchange of error information between error prone routines and error handlers and the logic that the error handlers will use to sort through the problem. 

Additional Resources:

Building a JAR File
Table of Contents
Throwing Errors


Graphics & Media Lab. >> Библиотека | Курсы | Графикон

Hosted by Graphics & Media Lab
http://graphics.cs.msu.su
lab_logo
mailto: Laboratory