【发布时间】:2020-08-19 15:01:11
【问题描述】:
动机:我想记录文件名、行号、函数名、错误代码等来帮助分析错误
Rust 有 ? 来进行错误处理。如果? 中有错误,我想将信息记录到文件中。如何做到这一点?
代码:
let a = do_some_function_may_return_error()?; // Does it auto log the error info when error occurs?
let b = a.do_another_function_may_return_error()?; // Does it auto log the error info when error occurs?
【问题讨论】:
-
您可能对tracing framework 感兴趣,尤其是使用tracing attributes 注释相关函数。
-
谢谢。如果
?无法自定义。我想我想在跟踪框架之上实现一个像try这样的宏。然后我可以记录文件名、行号、错误代码等来帮助分析错误
标签: error-handling rust error-logging