DOC PREVIEW
UF COP 5555 - Loops Exceptions

This preview shows page 1-2-3 out of 8 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 8 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 8 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 8 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 8 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

AssignmentsDijkistra’s Guarded doVariations on WhileGoto Considered HarmfulExceptionsHow is an Exception RepresentedHandling ExceptionsFinalizationAssignments•A sample main program for Project 2 phase 2 is contained in:http://www.cise.ufl.edu/~jnw/COP5555/Assignments/Programs/phase2main.c•It reads an input program with a filename of form file.g, places executable code in a file named file.c, then execs the g++ compiler to create a file named file, that is the executable version of file.c, which is equivalent in meaning to file.g.•My sample program does not put translated garnet code in the program, but it does create a valid C++ program (hello world).•Homework Due Tuesday: 6.4, 6.8, 6.29, 6.48Dijkistra’s Guarded dodo B1 -> S1| B2 -> S2...| Bn -> Snod•This behaves like a guarded if that is repeatedly executed until all guards are false.•The typical while (B) S is equivalent todo B -> S odVariations on While•Termination test at end rather than beginning of control structure:do S while (B);•Mid-loop termination (break) or repitition (continue)•for-loop of Cfor (initialization; go-ahead; update) S;•foreach x sequence S•CLU Iterator (limited coroutine concept employing yield construct to swap context ).Goto Considered Harmful•Dijkstra’s letter http://www.acm.org/classics/oct95/ (dubbed Goto Statement Considered Harmful) put forth the proposition that goto statements make it difficult to determine how to chart the progress of a process.•To help programmers avoid the use of goto, many languages include labelled control structures and allow breaks to exit multiple control constructs.Exceptions•An exception is said to be raised when erroneous computations are requested or detected.•Exceptions cause control to transfer without any explicit representation upon the part of the programmer.•Most programming languages cause a program to terminate if an exception is raised unless some exception handler is specified.•Exception handlers are used to recover a program’s execution (and avoid termination) when an exception has been raised.•PL/I had a primitive form of exception handling with its ON conditions that specified an action to take when an error of a given type occurred. ON conditions were executable statements (providing dynamic scope) and any state repair took place in the referencing environment in effect when the ON was executed rather than when the exception occurred.•John Goodenough published several papers concerning structured exception handling and some of his ideas were implemented in the CLU programming language. It allowed any block to contain an exception handler which would list named exceptions and associated actions. Raising an exception terminates the current block and initiates execution of the associated exception handler in that block. Unhandled exceptions are raised again in the calling context.How is an Exception Represented•Exceptions may or may not contain data.•Exceptions may or may not be arranged in a class hierarchy.•Ada exceptions are arranged in a class hierarchty but have no data associated with them.•The Dylan language provides a class hierarchy of conditions, some of which contain data and some of which do not.•C++ allows any class to be treated as an exception class.Handling Exceptions•The most common approach to exception handling nowadays is to use a try-catch block similar to that of CLU.•The try clause specifies the normal execution. If execution of the try clause raises an exception, then an object corresponding to the exception is created and the try clause terminates. •Each catch clause can handle one type of exception. If an exception has been raised, the clause trapping the type of exception raised by the try will be executed.Note: this means that the language must be able to determine the class to which the raised exception belongs. This requires some form or run-time type identification (RTTI) mechanism to be provided.•If an exception is not handled by a catch block, it is raised again in the context containing the try-catch, and is handled by the nearest dynamically enclosing try-catch.•If an exception is handled by a catch block, all major languages nowadays terminate the try-catch after the catch completes. This behavior (known as the termination model) has completely overwhelmed the PL/I behavior (known as the resumption model).Finalization•The term finalization is used to describe a block of code that is to be executed either on termination of a block or when an object is deleted.•Java provides a finally clause for its try-catch blocks that will execute on exit from the block no matter whether exit is from the try block or a catch block. The finally clause may close files, or perform other cleanup•Those languages that provide finalization of objects do not need to perform object clean-up in an exception handler finalization clause. Such clean-up will be handled as the objects themselves go out of scope.•Other forms of finalization may be required for a block, but I’ve yet to see a good example. If you ever find one, please send it to


View Full Document

UF COP 5555 - Loops Exceptions

Download Loops Exceptions
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Loops Exceptions and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Loops Exceptions 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?