Home > OS >  Split an exception into it's exception type and message
Split an exception into it's exception type and message

Time:07-15

I have program which requires a "check mode" in which all errors are logged but not raised to accommodate this I have built a log_crash function which takes an error type and an error message this all works well but I also have some instances where I need to just wrap everything in a big try/except block and catch any exception thrown. E.g.

try:
    #code block
except Exception as Err:
    log(Err)

I'm trying to find how I can split the error back up into the message and error type (the x in the code below):

def split_err(err):
    x


err = Exception("this is an exception")
err_type, message = split_err(err)

Thanks

CodePudding user response:

err = Exception("This is Exception")
err_type = err.__class__ # This will return error type
error_message = err.args[0] # this will return error message
  • Related