shaneangel
发贴: 0
积分: 0
|
于 2003-10-16 09:15
1.Core Concept: Regarded Region: The source code within the try clause of your programme.
Ducking Exception: If the method provided a catch clause for a particular exception, this method is called “ducking” exception.
Exception Matching: When an exception is thrown, Java will try to find a catch clause for the exception. If it doesn’t find one, it will search for a handler for a supertype of the exception. If it doesn’t find a catch clause that matches a superytpe for the exception, then the exception is propagated up the call stack. This process is called Exception Matching.
Catch or Specify Requirement: Each method must either handle all checked exceptions by applying catch clause or list each unhandled checked exception as a thrown exception. This rule is referred to as Java’s catch or specify requirement.
Checked Exception: the all subclasses of Exception are called checked Exception, in this case it’s necessary to catch this type of exception or specify it by used throws clause followed by define the class.
Unchecked Exception: the all subclasses of Error or RuntimeException, these exception need not to be caught or specified, it just represent program bugs, like RuntimeException.
3.Formatting: (Pseudocode) try { //This is the first line of the “guarded region” //that is governed by the try keyword. //Put code here that might cause some kind of exception. //We may have many code lines here or just one. // This clause is necessary in handling to exception. } catch (NamingException VariableofException) { //Put code here that handles this error. //This is the next line of the exception handler. //This is the last line of the exception handler. //This clause not required. } finally { //Put code here that you want to do that regardless if the exception occurred. //Normally, used to release the system resource and to perform any needed cleanup //for the try clause. This clause not required. }
4.The flow control in Exception handler As we are similar, the flow enter into the try block code directly, if have anything happened, it can go downward step by step, but the code in which catch clause isn’t be executed, then go into the finally clause to execute the code in it, last the code will be executed that following the finally clause. Once the any type of exception will be occurred, this flow control changes into the first line within catch clause that is relative with the NamingException. Immediately then the finally clause will be executed.
5.The benefits of using Exception Handler Mechanism There are three primary benefits of exception handling: ² Exception Handlers Are Separated From A Method’s Primary Logic. ² Similar Errors Can Be handled Together. ² Exception Propagation.
6.How to define the Exception belong to you Create your own exceptions by subclassing any existing Exception class or any of its subclasses. Each exception has two constructors: non-arguments default constructor, and one that accepts a String as parameter. Of course, this class could have all methods that derived from the supertype of particular exception.
7.The useful method of the Exception fillInStackTrace() It is used primarily to hide the original location where the exception was created. The stack information placed in the exception object when it was created is replaced with the stack trace to the current location when its method is called. printStackTrace() Print the stack trace information, it will indicate the exception was thrown from the method that contained the throw keyword, not the location from which the original exception was thrown. getMessage() Return the string that instantiated an Exception pass into it as arguments that are String type.
shaneangel edited on 2003-10-16 09:19
|