question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Catching unhandled exceptions in Python

See original GitHub issue

Hi there, is there any option to catch unhandled exceptions from within a Python program (no Flask/Django)?

I can do this in Azure Application Insights as follows:

#!/bin/env python
import applicationinsights.exceptions
applicationinsights.exceptions.enable( '********-****-****-****-************' )
print 2/0

The above code would report a ZeroDivisionError exeception to the Azure Application Insights console.

Regards, Danilo

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
lingfishcommented, Sep 16, 2018

Ah, very nice! I kinda hoped so, it just isn’t super clear in the doco. Not sure if that is able to be contributed to or not? Otherwise, perhaps a suggestion for it to be added 😉

1reaction
lingfishcommented, Sep 16, 2018

I’d like to know this too. Just started using Sentry, and thought this was exactly the point of it, to catch unhandled exceptions in stock Python so that devs didn’t have to go hunting through logs.

A big fat except: seems heavyhanded.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Python: how can I handle any unhandled exception in an ...
Use sys.excepthook to replace the base exception handler. You can do something like: import sys from PyQt4 import QtGui import os.path ...
Read more >
8. Errors and Exceptions — Python 3.11.1 documentation
Errors detected during execution are called exceptions and are not unconditionally fatal: you will soon learn how to handle them in Python programs....
Read more >
Learning (not) to Handle Exceptions - Python for the Lab
We are going to cover from the basics of error handling to defining your own exceptions. You will learn why sometimes it is...
Read more >
Exception Handling - Python Module of the Week - PyMOTW
Unhandled Exceptions ​​ excepthook to a function that takes three arguments (error type, error value, and traceback) and let it deal with unhandled...
Read more >
Python Exceptions: An Introduction - Real Python
As you saw earlier, when syntactically correct code runs into an error, Python will throw an exception error. This exception error will crash...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found