Error handling IronRuby堆栈跟踪
你好!我们正在做一个IronRuby项目。有一个C#WPF应用程序。我们为该应用程序编写了一个模块。当IronRuby中出现错误时,应用程序将显示一个消息框。它只显示错误消息。它没有显示是哪个Ruby脚本引发了错误Error handling IronRuby堆栈跟踪,error-handling,stack-trace,ironruby,callstack,Error Handling,Stack Trace,Ironruby,Callstack,你好!我们正在做一个IronRuby项目。有一个C#WPF应用程序。我们为该应用程序编写了一个模块。当IronRuby中出现错误时,应用程序将显示一个消息框。它只显示错误消息。它没有显示是哪个Ruby脚本引发了错误 我们如何让IronRuby显示引发错误的ruby文件?我找到了一个解决方法,您需要用begin rescue将代码包装为如下: begin # Write your ruby code here, that can have an error rescue SyntaxError
我们如何让IronRuby显示引发错误的ruby文件?我找到了一个解决方法,您需要用begin rescue将代码包装为如下:
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解释器在错误发生时抛出异常,所以您需要捕获它并将其堆栈跟踪写入messagebox。如果您找到了另一种方法,请将其写在此处我已经找到了一种解决方法,您需要使用begin rescue将代码包装为如下所示:
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解释器在错误发生时抛出异常,所以您需要捕获它并将其堆栈跟踪写入messagebox。如果你有别的办法,请写在这里