New Issue: Make stack trace accessible in a caught error

16277, “ben-albrecht”, “Make stack trace accessible in a caught error”, “2020-08-21T19:55:37Z”

Feature request: Make stack trace accessible in a caught error.

Motivation: In language interop, one might want to catch all Chapel errors and translate them to errors to be thrown in the language calling Chapel. It would be nice to be able to include the stack trace information when translating errors from Chapel to another language.

Some design questions

  1. How should the stack trace be represented?
    • It could be as simple as a multi-line string stored as a field on the Error class
    • It could be as complex as a new traceback type that supports operations like indexing the stacks, querying filenames, line numbers, and offsets
  2. Should the stack trace field be disabled when --fast is thrown for performance reasons?
  3. What should the field / getter method be called?
  • stacktrace / stackTrace
  • traceBack / traceBack
  • backTrace / backTrace

Here’s a short straw-example of what this feature could look like:

try {
  foo();
} catch SomeError as e {
  writeln('An error occurred here:\n', e.stackTrace);
}

As a reference, Python has a whole module for extracting, formatting, and printing stack tracebacks. The above example would look something like this in Python:

import traceback

try:
    foo()
except SomeError as e:
    tb = traceback.format_exc()
    print('An error occurred here:\n, tb)