How can I get error message?
try:
...# some operations
except:
sock.sendto(err_msg,0,addr) # send client err_msg from exception
Jump to PostDo not use unconditional except, you stop for example key interrupt.
Check the error code you get without except, say it is TheErrorType then do
try: #your stuff with potential for interrupt as little lines as possible except TheErrorType as e: print 'Got error %s in …
Do not use unconditional except, you stop for example key interrupt.
Check the error code you get without except, say it is TheErrorType then do
try:
#your stuff with potential for interrupt as little lines as possible
except TheErrorType as e:
print 'Got error %s in the input, ignoring' % e
else:
# normal stuff if interrupt did not happen
finally:
# clean up code common for both cases
Take a look at the trackback docs. You possibly want traceback.format_exc() or extract_tb(traceback[, limit])
Thank you tonyjv and woooee.
I'm using tonyjv's syntax with sys.exc_info() function:
exc_type, exc_value, exc_trbk = sys.exc_info()
print(exc_type,exc_value)
ret_str = str(exc_value)
sock.sendto(ret_str.encode('ascii'),0,addr)
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.