Catch all exceptions, what exception was raised?

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
Post Reply
Khyrtsi
Posts: 5
Joined: Sat Nov 12, 2016 7:28 am
Location: Finland
Contact:

Catch all exceptions, what exception was raised?

Post by Khyrtsi » Sun Mar 19, 2017 4:29 pm

If I catch all exceptions, how can I see what exception was raised?

I know that it's normally considered bad practise to catch all, but I would like to log the exception to somewhere (network or lcd) and not just freeze.

User avatar
pythoncoder
Posts: 1960
Joined: Fri Jul 18, 2014 8:01 am

Re: Catch all exceptions, what exception was raised?

Post by pythoncoder » Sun Mar 19, 2017 4:38 pm

Code: Select all

paste mode; Ctrl-C to cancel, Ctrl-D to finish
=== try:
===     1/0
=== except Exception as e:
===     print(e)
=== 
division by zero
>>> 
Peter Hinch

Post Reply