Newsgroups: comp.lang.modula3
Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!think.com!sdd.hp.com!elroy.jpl.nasa.gov!decwrl!pa.dec.com!src.dec.com!gnelson 
From: gnelson (Greg Nelson)
Subject: Re: Local exceptions
In-Reply-To: Message of Sat, 18 May 91 02:46:05 PDT
    from stolfi (Jorge Stolfi)
    <9105180946.AA24240@jumbo.pa.dec.com>
To: m3
Message-ID: <9105182122.AA09401@jumbo.pa.dec.com>
Cc: stolfi (Jorge Stolfi)
X-Folder-Carbon: sent
Date: Sat, 18 May 91 14:22:42 PDT
Lines: 47


Jorge Stolfi asks,

    I notice that Modula-3 allows exception declarations only at the top
    level of modules and interfaces.
    
    What was the point of this restriction?  (Local exceptions seem a pretty
    natural concept.)

You can make sense of local exceptions, but the benefits are not worth
the cost of the effort.  I suppose that with local exceptions, you
want the following block to be a checked runtime error:

    EXCEPTION E;
    BEGIN
      TRY 
        EXCEPTION E; BEGIN RAISE E END
      EXCEPT
        E: (*Skip*)
      END
    END

That is, you want the different exception declarations to produce
different exceptions.  Now consider:

    PROCEDURE P(b: BOOLEAN) = 
      EXCEPTION E;
      BEGIN
        TRY
          IF b THEN 
            P(NOT b)
          ELSE
            RAISE E
          END
        EXCEPT
          E: (* Skip *)
        END
      END P;

Do you want P(FALSE) to be an unhandled exception?  That is, do the
declarations of EXCEPTION E at the two levels of recursion introduce
different exceptions, or the same exception?  If they introduce the
same exception, then the procedure call behaves differently than
its body would; semanticists will not like this.  If they introduce
different exceptions, programmers might well be surprised.  The Modula-3
committee could not find any real use for local exceptions, and
therefore decided that the wisest choice was "none of the above".
