-
Notifications
You must be signed in to change notification settings - Fork 3
NEP23 Panic statement
This proposal introduces a new way to exit a process with a diagnostic message and stack trace, similar to an uncatchable exception.
In some situations there are conditions that are not expected and cannot be reasonably handled (by an exception handler). Examples include the following kinds of internal conditions:
- Division by zero
- Array bounds access out of range
There can also be programmer-defined conditions that indicate a logic error or some condition that "can't happen".
One approach to handling such conditions is to define a new exception type, and RAISE
that exception when the condition occurs. However, this requires that the programmer make the effort to define such an exception, while at the same time not intending that it ever be caught.
Another approach takes a couple of statements:
textio.writeLine(textio.stderr, "existing because of error")
EXIT PROCESS FAILURE
It is desirable to have a more convenient, lower friction method of handling such conditions.
The proposed new PANIC
statement is very simple:
PANIC message
where message
is a string describing the condition. For example:
PANIC "this should not happen"
or
PANIC "counter value \(counter) exceeds 10"
When the PANIC
statement is executed, the diagnostic message is printed to stderr and a stack trace (if available) is printed. The process then exits with failure (exit code 1).