an exception traceback and continue - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: an exception traceback and continue (/thread-7592.html) |
an exception traceback and continue - Skaperen - Jan-17-2018 i would like to try a given block of statements, and if there is any exception, just keep on running like: try: whatever goes here ... except: passbut ... i'd also like to get the same full traceback and exception message output like i would get if i did not use the try/except and continue running. in another case i'd like to have only the exception message output without the traceback. in a 3rd case i'd like to capture the traceback and exception message into some data object. in a 4th case same as the 3rd but only capture the message. the 4th case will not be needed if the is some way to extract the message from the whole capture. RE: an exception traceback and continue - Larz60+ - Jan-17-2018 I posted a snippet on manipulating the call stack, which is what a traceback does, here: https://python-forum.io/Thread-Walking-the-python-call-stack-without-leaks RE: an exception traceback and continue - Gribouillis - Jan-17-2018 You can invoke the functions from the traceback module to obtain this, for example import traceback as tb while True: n = input('Give me an integer: ') try: n = int(n) except ValueError: tb.print_exc() else: print('Got:', n) RE: an exception traceback and continue - snippsat - Jan-17-2018 Sound like a logging setup. Example: import my_log def add(x, y): try: return(x + y) except Exception as error: my_log.logger.exception('msg') if __name__ == '__main__': my_log.logger.info('Start') value = add(33, '50') my_log.logger.debug(value) my_log.logger.info('Finish') print(value)One run without error and one with '50' There are many cases where not give all error message to users make sense, server,GUI...ect. logg.log : setup my_log.py :RE: an exception traceback and continue - Skaperen - Jan-17-2018 i'm wanting to do some things with this for debugging tools. |