Thursday 29 November 2012

EXCEPTION HANDLING.....CONT

 CATCHING AN EXCEPTION USING TRY AND CATCH:
      Before we start, let's provide some language  The phrase "exception" indicates "exception condition" and is an incident that change the regular system circulation. A lot of factor can cause to exclusions. such as components failing source fatigue and excellent old insects. When an remarkable occasion happens in coffee an exception is said to be "thrown" the value that's accountable for doing something about the exception is known as an "exception handler" and it "catches" the tossed exception.

     The try is used to described a prevent of value in which exclusions may happen. This prevent of value is known as a included area ( which really indicates "risky value goes here") one or more capture sessions go with a certain exception (or list of exceptions-more on that later) to a prevent of value that manages. It the primary objective of capture the exception from try prevent. Here's how it looks in pseudocode.


    try
    // this is the first range of the "guarded region"
    // that is controlled by the keyword and key phrase.
    // put value here that might cause some type of exception.
    // we may have many value collections here or just one.
    }
    capture (MyFirstException)  {
    // put value here that manages this exception.
    // this is the next range of the exception owner.
    // this is the last range of the exception owner
    }
    catch(MySecondException) {
    // put value here that  manages this exception
    }
    
    // some other unguarded (normal, non-risky) value begins here

  In this pseudocode example collections 2 through 5 represent the covered area that is controlled by the stipulation . Line 7 is an exception owner for an exception of type My Second Exception. Observe that capture prevent instantly adhere to the try prevent. This is a need if you have one or more capture prevent they must instantly adhere to the try prevent. Furthermore the capture prevents they must all adhere to each other without any other declaration or prevents in between. Also the transaction in which the record prevents appear issues as we'll see a little later.

      Exemption of the covered area begins at range 2. If the system exception all the way previous range 5 with no exclusions being tossed performance will transform to range 15 and proceed downwards. However if whenever they want in collections 2 through 5 ( the try prevents ) an completes is tossed of type My First Exception performance will instantly  exchange to range 7 collections 8 through 10 will then be implemented so that the whole capture prevent operates and then exertion will exchange to range 15 and proceed. Observe that that if an exception happened on say line3 of the try prevent the relax of the collections in the try avoid (4 and 5) would never be implemented once management leaps to the capture prevent it never profits to finished the stability of the try prevent

No comments:

Post a Comment