try except and backtrace print log

C programming, build, interpreter/VM.
Target audience: MicroPython Developers.
Post Reply
User avatar
cederom
Posts: 16
Joined: Tue Oct 26, 2021 1:37 am
Contact:

try except and backtrace print log

Post by cederom » Fri Jan 28, 2022 3:42 am

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 :-)
--
CeDeROM, SQ7MHZ, https://www.tomek.cedro.info


User avatar
cederom
Posts: 16
Joined: Tue Oct 26, 2021 1:37 am
Contact:

Re: try except and backtrace print log

Post by cederom » Fri Jan 28, 2022 4:17 am

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!! :-)
--
CeDeROM, SQ7MHZ, https://www.tomek.cedro.info

Post Reply