问题描述
可能会得到特定类型的错误
try:
raise newException(CatchableError,"some error")
except IOError as e:
echo e.msg
可能会出现任何错误,但是需要调用特殊函数来获取感觉确实错误的错误
try:
raise newException(CatchableError,"some error")
except:
let e = getCurrentException()
echo e.msg
有没有办法做到这一点?
try:
raise newException(CatchableError,"some error")
except e:
echo e.msg
解决方法
任何可捕获的错误都应扩展CatchableError
,因此这应该可以满足您的要求:
try:
raise newException(IOError,"some error")
except CatchableError as e:
echo e.msg