Bentley4
Bentley4

Reputation: 11038

Are there runtime errors(= exceptions) that do not generate a traceback in python?

Are there runtime errors(= exceptions) that do not generate a traceback? If yes, why do some runtime errors not generate tracebacks? could you give some examples?

Upvotes: 3

Views: 299

Answers (3)

Frédéric Hamidi
Frédéric Hamidi

Reputation: 263057

You can pass a very large value to sys.setrecursionlimit(), then enter an infinite recursive loop. The interpreter will crash without a traceback in that case.

However, that's only because the call to setrecursionlimit() effectively disables the fail-safe mechanism that would have turned a potential stack overflow into a Python exception.

Upvotes: 4

Ned Batchelder
Ned Batchelder

Reputation: 375814

There are no Python exceptions that don't produce tracebacks. As the other answers show, you can crash CPython hard, which don't produce tracebacks. If you could explain your interest in this, we might have more information.

Upvotes: 1

Andrew Walker
Andrew Walker

Reputation: 42500

Yes, I can think of at least one: segmentation faults.

>>> import faulthandler
>>> faulthandler._sigsegv()
Segmentation fault

The faulthandler module is specifically designed to help in such situations.

>>> import faulthandler
>>> faulthandler.enable()
>>> faulthandler._sigsegv()
Fatal Python error: Segmentation fault

Current thread 0xb76fe6c0
 File "<stdin>", line 1 in <module>
Segmentation fault

Upvotes: 4

Related Questions