-1

The trap mechanism in Mumps has similarities to the exception mechanism in many other language.

Most examples I have seen of trap usage is for catching unintentional errors.

Is there also a way intentionally trigger an error, which can be caught by a trap, in a way that is similar to throwing an exception?

I am working with GT.M V7.0. I’m learning about traps from here:

http://tinco.pair.com/bhaskar/gtm/doc/books/pg/UNIX_manual/ch13s06.html

Lii
  • 11,553
  • 8
  • 64
  • 88

1 Answers1

2

You can do this by setting the $ECODE variable.

See also https://docs.yottadb.com/ProgrammersGuide/errproc.html#ecode.

This is YottaDB but I think it will work for GT.M too.

SET $ECODE=",U13-User defined error trap,"

A simple thing that should work too: S X=1/0

Lii
  • 11,553
  • 8
  • 64
  • 88
Jens
  • 206
  • 1
  • 3
  • Ah, by settings `$ECODE` how simple! Thanks! – Lii May 13 '22 at 13:00
  • 1
    It seems like settings [`ZMESSAGE`](https://docs.yottadb.com/ProgrammersGuide/commands.html#zmessage) has a similar effect. – Lii May 13 '22 at 13:01