try: execpt:/ try: finally: behavior

Mark S. Riggle (sasmsr@zinfande.unx.sas.com)
Tue, 21 Jun 1994 15:20:28 GMT

The scope of exception clauses does not seem to be adjusted during
exception handling that is caught by a finally clause. If two
exception clauses are nested and an execption is raised to the
outermost one and a finally clause is triggered that raises an
exception to the inner one, the outer is lost. An example is worth a
lot here.

================================================================
my_exec= 'my_exec'
my_exec2= 'my_exec2'

def jjj(x):
try: # - outer try catching my_exec
try: # - inner try catching my_exec2
jjk(x) # - raise my_exec but on a finally, raise my_exec2
except my_exec2, val:
print 'execption my_exec2 raised', val
print 'foul up if this is printed' # - if my_exec raised
except my_exec, val:
print 'execption my_exec raised', val

def jjk(x):
try:
raise my_exec, x
finally:
raise my_exec2, x+1

>>> jjj(3)
execption my_exec2 raised 4
foul up if this is printed

==================================================================

The raised my_exec exception which was first encountered is lost.
IMHO, it seems the implementation should raise this as a error. When
the my_exec exception is raised, the scope of the except clause for
my_exec2 should not be valid. It should be treated in this case as if
there is no error handler for the my_exec2 exception.

While the example may seem rather artificial, it can easily arise
in applications, so I think it is a serious error.

-- 
=========================================================
Mark Riggle                         | "Give me LAMBDA or
sasmsr@unx.sas.com                  |  give me death"
SAS Institute Inc.,                 |
SAS Campus Drive, Cary, NC, 27513   |  
(919) 677-8000                      |