'Traps as exceptions

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



Solution 1:[1]

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

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Lii