Thursday 29 November 2012

EXCEPTION HANDLING CONT..........

Using finally:
     A lastly prevents clos value that is always executed at some point after the try prevent climate an exemption was tossed or not. Even if there is a come back declaration in the try prevent the lastly prevent finishes right after the come back declaration is experienced and before the come back executes

    This is the right place to shut your information launch your system electrical sockets and execute any other clean-up your value needs. If the try prevents finishes with no different the lastly prevent is implemented soon after the try prevent finishes if there was an exemption tossed the lastly prevent finishes soon after the appropriate capture prevent finishes the main objective of lastly prevents is to sustain the clean-up code

     Let's look at another pseudocode example:

       try{
    // This is the first range of the "guarded region"
    }
    capture (MyFirstException) {
    // put value here that manages this exemption.
    }
    capture  (My First Exception) {
    // put value here to launch any source we
    }
    lastly {
    // put value here to launch any source we
    // assigned in the try clause
    }
    // More value here


As before performance  begins at the first range of the try prevent range 2 If there are no exclusions tossed in the try prevent performance exchange to range 11 the first range of the lastly prevent. on the other hand if a My Second Exception id thrown while the value in the try prevent is executing performance exchanges to the first range of that exemption owner range 8 in the capture stipulation. After all the value in the capture stipulation is implemented the system goes to range 11 the first range of the lastly clause

    do it again after me : lastly always runs! OK we'll have to improve that a little but for now begins losing in the concept lastly always operates if an finishes is tossed lastly operates if an exemption is not tossed lastly operates if the omission is captured lastly operates if the exemption is not captured lastly operates later we'll look at the few circumstances in which lastly might not run or finish.

      Keep in mind lastly conditions are not needed if you don't create one your value will gather and run excellent in fact if you have no source to fresh up after your tr prevent finishes you probably don't need a lastly stipulation. Also because the compiler doesn't even need capture situations sometimes you'll run across value that has a try prevent instantly followed by a lastly prevent such value is useful when the exemption is going to be approved back to the contacting  technique as described in the next area. Using a lastly prevent allows the clean-up value to finishes even when there isn't a capture stipulation 

No comments:

Post a Comment