defprocess(num1, num2, file): try: result = num1 / num2 with open(file, 'w', encoding='utf-8') as f: f.write(str(result)) except ZeroDivisionError: print(f'{num2} can not be zero') except FileNotFoundError: print(f'file {file} not found') except Exception as e: print(f'exception, {e.args}')
file_not_found_error [Errno 2] No such file or directory: 'result/result.txt' zero_division_error division by zero exception <class 'TypeError'> unsupportedoperandtype(s) for /: 'int' and 'list'
zero_division_error division by zero connect_timeout HTTPConnectionPool(host='notfound.com', port=80): Max retries exceeded with url: / (Caused by ConnectTimeoutError(<urllib3.connection.HTTPConnection objectat 0x10d5b9310>, 'Connection tonotfound.comtimedout. (connecttimeout=1)'))
from functools import wraps import inspect import logging
getargspec = None if getattr(inspect, 'getfullargspec', None): getargspec = inspect.getfullargspec else: # this one is deprecated in Python 3, but available in Python 2 getargspec = inspect.getargspec
def_try(self, f): @wraps(f) defwrapper(*args, **kwargs): ret = None try: ret = f(*args, **kwargs)
# note that if the function returned something, the else clause # will be skipped. This is a similar behavior to a normal # try/except/else block. if ret isnotNone: return ret except Exception as e: # find the best handler for this exception handler = None for c in self.except_.keys(): if isinstance(e, c): if handler isNoneor issubclass(c, handler): handler = c
# if we don't have any handler, we let the exception bubble up if handler isNone: raise e
# if in debug mode, then bubble up to let a debugger handle debug = self.debug if handler in self.force_debug: debug = True elif handler in self.force_handle: debug = False if debug: raise e
# invoke handler if len(getargspec(self.except_[handler])[0]) == 0: return self.except_[handler]() else: return self.except_[handler](e) else: # if we have an else handler, call it now if self.else_ isnotNone: return self.else_() finally: # if we have a finally handler, call it now if self.finally_ isnotNone: alt_ret = self.finally_() if alt_ret isnotNone: ret = alt_ret return ret return wrapper
def_except(self, *args, **kwargs): defdecorator(f): for e in args: self.except_[e] = f d = kwargs.get('debug', None) if d: self.force_debug.append(e) elif d isnotNone: self.force_handle.append(e) return f return decorator
Warning: get_headers(): SSL operation failed with code 1. OpenSSL Error messages:
error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57
Warning: get_headers(): Failed to enable crypto in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57
Warning: get_headers(https://static.shanhubei.com/qrcode/qrcode_viewid_11577.jpg): failed to open stream: operation failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57