Search code examples
pythonuser-interfacevalueerror

Is there away to use ValueError terminal output?


I was wondering if there is a way to use the terminal output for ValueError when found? In my case, it works perfectly as is. See attached image. If I could just display it on my GUI, it would instantly improve my UX. I can't imagine having to write codes to capture the error in question '*5'. Does it have something to do with message.py? How do I get there?

on my wish list

as per Amir


Solution

  • In general, this is how you catch and print an exception:

    try:
        # doing something that raises an error
        a = float('*5')
    except ValueError as e:
        error_msg = repr(e)  # this is the error message
        print('Got a ValueError exception!')
        print(error_msg)