Question: how to find the exact line number and module where an exception happens?

I have my code in mla. Using try/catch, I am able to capture an error that happend deep in some call chain. But it is hard to know the exact location where this error happened.

I use StringTools:-FormatMessage( lastexception[2..-1] inside the catch clause to print the exception. But this only prints the message. It does not tell me exactly which line/function/module this happened.

Is there a way to display these information?  Using debugger and stoperror all did not help at all. It does not stop at the line where the error happened. not sure why. I tried it many times. may be I am not using it correctly?

Is it possible to display may be the trace of the calls inside the catch of the try? To know the actual statement that generated the error? Now each time I get an exception, I have to step into the debugger line by line until  I get to the place where the error was which is time consuming. Here is a MWE

 

restart;
A:=module()  
  local B:=module()
     export foo:=proc(n)
         1/n;
     end proc;
  end module;

  export main:=proc()
    try
       B:-foo(0);
    catch:
      print("error happened", StringTools:-FormatMessage( lastexception[2..-1] ));
    end try;
  end proc;

end module;

And now

    A:-main()

                "error happened", "numeric exception: division by zero"

I'd like to get more information than the above as I said. Line number/proc name/module name or stacktrace showing the calls made up to where the exception started (similar to output from where command in debugger).

The above was done in worksheet. My actual code in inside .mla build from lots of .mpl files.

Maple 2021.2 on windows

Please Wait...