[Python] 快速套用 try-except 到 method 上 (使用 functools)
- 2025.01.06
- functools try statement (try-except)
import functools
def catch_exception(func):
  @functools.wraps(func)
  def wrapper(*args, **kwargs):
    try:
      return func(*args, **kwargs)
    except Exception as e:
      print 'Caught an exception in', f.__name__
  return wrapper
class ...[(...)]:
  @catch_exception
  def calc(self):
    ...
        
Last Updated on 2025/01/12 by A1go
 
	
           
  