[M3devel] RuntimeError doesn't work quite as advertised

Mika Nystrom mika at async.caltech.edu
Mon Apr 27 09:50:44 CEST 2009


Maybe someone else knows more about this than me...

The following program:

MODULE Main;
IMPORT RuntimeError, IO;

PROCEDURE Range() = BEGIN EVAL VAL(-1,CARDINAL) END Range;

PROCEDURE Assert() = BEGIN <*ASSERT FALSE*> END Assert;

PROCEDURE NilJump() = VAR x : PROCEDURE() := NIL; BEGIN x() END NilJump;

PROCEDURE NilDeref() =
  VAR x : REF INTEGER := NIL; b : INTEGER;
  BEGIN b := x^ END NilDeref;

PROCEDURE NilMethod() =
  TYPE T = OBJECT METHODS m() END;
  VAR t : T; BEGIN t.m() END NilMethod;

BEGIN 
  WITH ps = ARRAY OF PROCEDURE() { Range, Assert, NilMethod, NilJump, NilDeref } DO
    FOR i := FIRST(ps) TO LAST(ps) DO
      TRY
        ps[i]()
      EXCEPT
        RuntimeError.E(e) => IO.Put("RuntimeError: " & RuntimeError.Tag(e) & " \n")
      END
    END
  END
END Main.

yields the following result:

(1053)trs80:~/test/src>../FreeBSD4/prog
RuntimeError: An enumeration or subrange value was out of range. 
RuntimeError: <*ASSERT*> failed. 


***
*** runtime error:
***    Segmentation violation - possible attempt to dereference NIL
***    pc = 0x8048a71 = NilMethod + 0x10 in ../src/Main.m3
***

Abort

Seems to me I ought to see a few more exceptions and not a crash.

I'm happy to investigate a bit more, but does anyone have a clue where
to begin?

     Mika



More information about the M3devel mailing list