How to catch all exceptions of an old style class in python?

In code where there are different old-style classes such as this one:

class customException: pass 

and exceptions arise in this way:

 raise customException() 

Is there a type to catch all these exceptions in the old style? eg:

 try: ... except EXCEPTION_TYPE as e: #do something with e 

Or at least is there a way to catch everything (old and new style) and get the exception object in a variable?

 try: ... except: #this catches everything but there is no exception variable 
+6
source share
1 answer

The only solution I can think of is to use sys.exc_info

 import sys try: raise customException() except: e = sys.exc_info()[1] # handle exception "e" here... 
+3
source

All Articles