Always, on every assignment, please write your name legibly as it appears on your University ID and on the class list!
This assignment is dominated by review questions that are not as much specific to the material in the book as they are to material you should have learned in prior courses or work experience.
You should have learned about some such mechanism in your programming language concepts course, a prerequisite for 22C:116!
In Pascal, there is no built-in notion of exception handling, but the language allows non-local goto statements, and (to the surprise of many) these are sufficient. Any procedure or function that may raise an exception must take the handler as a procedure parameter. To raise the exception, simply call the procedure that was passed as a handler. This procedure never returns! Instead, it does a non-local goto, abandoning the execution context in which it was called and jumping to the end of the block in which it was declared. This is illustrated below:
procedure MightRaiseException( Procedure Exception ); begin ... if trouble then Exception; ... end; procedure HandlesException; label 999; procedure Handler; begin ... code to handle exception ... goto 999 end; begin ... MightRaiseException( Handler ); ... 999: endThe Problem: Write code in C or C++, using the C standard library routines setjmp() and longjmp() to demonstrate the construction of an exception handler in C or C++ that uses logic parallel to the Pascal code illustrated above. Information on setjmp() and longjmp() is available in the standard reference books for C and it is available on any Unix system using the man command.