How can I get error message?
try: ...# some operations except: sock.sendto(err_msg,0,addr) # send client err_msg from exception
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
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)