Page 1 of 1

try except and backtrace print log

Posted: Fri Jan 28, 2022 3:42 am
by cederom
Hello world :-)

My application catches all Exceptions. I would like to log them and upload to remote server to have insight on the status and possible issues with sensors remotely.

Catching Exception as e and then printing str(e) only gives me the error message. But I would also like to catch the backtrace as it is produced to console without try/except. In Python there is a backtrace module for that, but I cannot find it in a MicroPython. I am sure something like this exist here because backtrace is printed out on error in REPL.

How can I catch and print out the backtrace from an exception in MicroPython?

Any hints welcome :-)

Re: try except and backtrace print log

Posted: Fri Jan 28, 2022 4:10 am
by dhylands

Re: try except and backtrace print log

Posted: Fri Jan 28, 2022 4:17 am
by cederom
dhylands wrote:
Fri Jan 28, 2022 4:10 am
Here's an example for you: https://github.com/dhylands/upy-example ... int_exc.py
Look at sys.print_exception: http://docs.micropython.org/en/latest/l ... _exception
Wow! Thank you Dave!! :-)