IronRuby 堆栈跟踪

发布于 2024-10-08 03:27:40 字数 165 浏览 0 评论 0原文

问候!我们正在开发一个 IronRuby 项目。有一个 C# WPF 应用程序。我们为该应用程序编写了一个模块。当 IronRuby 中出现错误时,应用程序会显示一个消息框。它仅显示错误消息。它不显示哪个 Ruby 脚本引发了错误。

我们如何让 IronRuby 显示引发错误的 ruby​​ 文件?

Greetings! We're working on an IronRuby project. There's a C# WPF application. We wrote a module for that application. When an error is raised in IronRuby, the application shows a message box. It only shows the error message. It does not show which Ruby script raised the error.

How do we get IronRuby to display the ruby file that raises the error?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

饮惑 2024-10-15 03:27:40

我找到了一个解决方法,你需要用 beginrescue 包装你的代码,如下所示:

begin
  # Write your ruby code here, that can have an error
rescue SyntaxError, NameError => boom
  str = "String doesn't compile:\n " + boom
  puts str
  puts boom.backtrace.join("\n")
rescue StandardError => bang
  str = "Error running script: " + bang
  puts str
  puts bang.backtrace.join("\n")
rescue
  puts "Unknown error happened"
end # rescues 

似乎 Ruby 解释器在发生错误时抛出异常,因此你需要捕获它并将其堆栈跟踪写入消息框。如果您找到其他方式,请写在这里

I have found a workaround for this, you need to wrap your code with begin rescue like this:

begin
  # Write your ruby code here, that can have an error
rescue SyntaxError, NameError => boom
  str = "String doesn't compile:\n " + boom
  puts str
  puts boom.backtrace.join("\n")
rescue StandardError => bang
  str = "Error running script: " + bang
  puts str
  puts bang.backtrace.join("\n")
rescue
  puts "Unknown error happened"
end # rescues 

Seem that Ruby interpreter throws an exception when error occurs, so you need to catch it and write its stack trace into messagebox. If you find another way, please write it here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文