Please print out the error code and do not print the traceback

Asked 2 years ago, Updated 2 years ago, 172 views

If you use pass in exception, you can't see what the error is at all, and if you don't take any action, there are a lot of tracebacks.

I want to know how to make it so that I can print only the error code and not print the traceback.

python exit traceback

2022-09-22 22:11

1 Answers

Then when an exception occurs

You can create a code that you do.

Write down your main routine like this

import sys, traceback

def main():
    try:
        #This is where the main code goes.
    except KeyboardInterrupt:
        print "Shutdown requested...exiting"
    except Exception:
        traceback.print_exc(file=sys.stdout)
    sys.exit(0)

if __name__ == "__main__":
    main()


2022-09-22 22:11

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.