Skip to main content
deleted 2 characters in body
Source Link
Chris_Rands
  • 41.7k
  • 15
  • 92
  • 126

Quoting the bounty text:

I want to be able to capture ANY exception even weird ones like keyboard interrupt or even system exit (e.g. if my HPC manger throws an error) and get a handle to the exception object e, whatever it might be. I want to process e and custom print it or even send it by email

Look at the exception hierarchy, you need to catch BaseException:

BaseException +-- SystemExit +-- KeyboardInterrupt +-- GeneratorExit +-- Exception 

This will capture KeyboardInterrupt, SystemExit, and GeneratorExit, which all inherit from BaseException but not from Exception, e.g.

try: raise SystemExit except BaseException as e: print(e.with_traceback"hello world!") 

Quoting the bounty text:

I want to be able to capture ANY exception even weird ones like keyboard interrupt or even system exit (e.g. if my HPC manger throws an error) and get a handle to the exception object e, whatever it might be. I want to process e and custom print it or even send it by email

Look at the exception hierarchy, you need to catch BaseException:

BaseException +-- SystemExit +-- KeyboardInterrupt +-- GeneratorExit +-- Exception 

This will capture KeyboardInterrupt, SystemExit, and GeneratorExit, which all inherit from BaseException but not from Exception, e.g.

try: raise SystemExit except BaseException as e: print(e.with_traceback) 

Quoting the bounty text:

I want to be able to capture ANY exception even weird ones like keyboard interrupt or even system exit (e.g. if my HPC manger throws an error) and get a handle to the exception object e, whatever it might be. I want to process e and custom print it or even send it by email

Look at the exception hierarchy, you need to catch BaseException:

BaseException +-- SystemExit +-- KeyboardInterrupt +-- GeneratorExit +-- Exception 

This will capture KeyboardInterrupt, SystemExit, and GeneratorExit, which all inherit from BaseException but not from Exception, e.g.

try: raise SystemExit except BaseException as e: print("hello world!") 
Bounty Awarded with 25 reputation awarded by CommunityBot
added 24 characters in body
Source Link
Chris_Rands
  • 41.7k
  • 15
  • 92
  • 126

Quoting the bounty text:

I want to be able to capture ANY exception even weird ones like keyboard interrupt or even system exit (e.g. if my HPC manger throws an error) and get a handle to the exception object e, whatever it might be. I want to process e and custom print it or even send it by email

Look at the exception hierarchy, you need to catch BaseException:

BaseException +-- SystemExit +-- KeyboardInterrupt +-- GeneratorExit +-- Exception 

This will capture KeyboardInterrupt, SystemExit, and GeneratorExit, which all inherit from BaseException but not from Exception, e.g.

try: # coderaise hereSystemExit except BaseException as e: passprint(e.with_traceback) 

Quoting the bounty text:

I want to be able to capture ANY exception even weird ones like keyboard interrupt or even system exit (e.g. if my HPC manger throws an error) and get a handle to the exception object e, whatever it might be. I want to process e and custom print it or even send it by email

Look at the exception hierarchy, you need to catch BaseException:

BaseException +-- SystemExit +-- KeyboardInterrupt +-- GeneratorExit +-- Exception 

This will capture KeyboardInterrupt, SystemExit, and GeneratorExit, which all inherit from BaseException but not from Exception, e.g.

try: # code here except BaseException as e: pass 

Quoting the bounty text:

I want to be able to capture ANY exception even weird ones like keyboard interrupt or even system exit (e.g. if my HPC manger throws an error) and get a handle to the exception object e, whatever it might be. I want to process e and custom print it or even send it by email

Look at the exception hierarchy, you need to catch BaseException:

BaseException +-- SystemExit +-- KeyboardInterrupt +-- GeneratorExit +-- Exception 

This will capture KeyboardInterrupt, SystemExit, and GeneratorExit, which all inherit from BaseException but not from Exception, e.g.

try: raise SystemExit except BaseException as e: print(e.with_traceback) 
Source Link
Chris_Rands
  • 41.7k
  • 15
  • 92
  • 126

Quoting the bounty text:

I want to be able to capture ANY exception even weird ones like keyboard interrupt or even system exit (e.g. if my HPC manger throws an error) and get a handle to the exception object e, whatever it might be. I want to process e and custom print it or even send it by email

Look at the exception hierarchy, you need to catch BaseException:

BaseException +-- SystemExit +-- KeyboardInterrupt +-- GeneratorExit +-- Exception 

This will capture KeyboardInterrupt, SystemExit, and GeneratorExit, which all inherit from BaseException but not from Exception, e.g.

try: # code here except BaseException as e: pass