Due to high demand expect some shipping delays at this time, orders may not ship for 3-4 business days.
0

Traceback Module, release 7,1.x
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Traceback Module, release 7,1.x

by PierreDeQuebec on Fri Jan 14, 2022 2:48 pm

Hi,

The method traceback.print_exception has the following arguments.

Code: Select all | TOGGLE FULL SIZE
traceback.print_exception(etype: Type[BaseException], value: BaseException, tb: types.TracebackType, limit: Optional[int] = None, file: Optional[io.FileIO] = None, chain: Optional[bool] = True) → None


But, it seems that the 'types' module is not yet implemented in CircuitPython. And the 'tb' argument is mandatory. Can you illustrate me with an example how to use the method?

Thank

Pierre

PierreDeQuebec
 
Posts: 26
Joined: Sun Jul 25, 2021 3:26 pm

Re: Traceback Module, release 7,1.x

by PierreDeQuebec on Fri Jan 14, 2022 3:42 pm

mpconfigboard.mk.txt
Remove '.txt'!
(1.37 KiB) Downloaded 1 time
There is an error in the title. CircuitPython version is as follows.
Adafruit CircuitPython 7.2.0-alpha.1-12-gd166834e0-dirty


I also attach the configuration file. I disabled some modules and 'froze' some libraries. I don't think this has any impact on my problem.

Pierre

PierreDeQuebec
 
Posts: 26
Joined: Sun Jul 25, 2021 3:26 pm

Re: Traceback Module, release 7,1.x

by danhalbert on Fri Jan 14, 2022 4:59 pm

The TraceBackType mentioned is just there for type-checking purposes, primarily for stubs. You can get a TracebackType object from some_exception.__traceback__, e.g.:

file tb.py:
Code: Select all | TOGGLE FULL SIZE
import traceback

def f():
    3/0

def g():
    f()

try:
    g()
except ZeroDivisionError as e:
    traceback.print_exception(None, e, e.__traceback__)

Running the above:
Code: Select all | TOGGLE FULL SIZE
>>> import tb
Traceback (most recent call last):
  File "tb.py", line 10, in <module>
  File "tb.py", line 7, in g
  File "tb.py", line 4, in f
ZeroDivisionError: division by zero

danhalbert
 
Posts: 2978
Joined: Tue Aug 08, 2017 12:37 pm

Re: Traceback Module, release 7,1.x

by PierreDeQuebec on Fri Jan 14, 2022 6:13 pm

Thank you for the answer. It works very well!

Pierre

PierreDeQuebec
 
Posts: 26
Joined: Sun Jul 25, 2021 3:26 pm

Please be positive and constructive with your questions and comments.