Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我想改变错误消息及其回溯的显示方式,而不需要rescue-ing 错误并调用自定义方法。有没有办法做到这一点?显示错误消息时是否有可以覆盖的方法?如果它是 Ruby 的内置部分,有人可以指点我格式化错误消息和回溯的相关 C 代码吗?
rescue
matugm 对 samuil 链接的问题的回答为我指明了方向。我可以做这个:
at_exit do print_the_altered_error_message($!) if $! and !$!.kind_of?(SystemExit) $stderr.reopen(IO::NULL) end
这对语法错误无效,但对于大多数其他情况,它会起作用。