I really though I'd find an answer online, but I couldn't. Is there any difference at all? People say a 'backtrace' is generated upon something throwing an exception, while a stack trace is a list of method calls from the point when the application was started to the point where the exception was thrown. If we supposed a stack-trace as an array, then the last element would be the method where the exception was thrown. Would it be the reverse case for a back-trace? In a programming language like Ruby, for example, if we have:
我真的虽然我在网上找到答案,但我不能。有什么不同吗?人们说在抛出异常时会产生“回溯”,而堆栈跟踪是从应用程序启动时到抛出异常的点的方法调用列表。如果我们将堆栈跟踪视为数组,则最后一个元素将是抛出异常的方法。回溯的情况是否相反?例如,在像Ruby这样的编程语言中,如果我们有:
begin
raise 1
rescue
p $!.backtrace ; p caller(0) #=> displays the back-trace, then the stack-trace
end
They will output 2 different arrays, which suggests to me there's something fundamentally different about them.
他们将输出2个不同的数组,这对我来说,它们有一些根本不同的东西。
1 个解决方案
#1
7
"Backtrace", "stack trace", "stack backtrace", etc. are names for the same thing. "Backtrace" specifically likely comes from the Linux tool of the same name. A stack trace doesn't refer to exceptions only - the current state of the program's call stack can always be displayed as a stack trace (which backtrace does, but so do many debugger views and tools). It's just helpful to output a stack trace during exceptions or errors.
“Backtrace”,“堆栈跟踪”,“堆栈回溯”等都是同一个名称的名称。 “Backtrace”特别可能来自同名的Linux工具。堆栈跟踪不仅仅涉及异常 - 程序调用堆栈的当前状态始终可以显示为堆栈跟踪(回溯可以显示,但许多调试器视图和工具也是如此)。在异常或错误期间输出堆栈跟踪很有帮助。
Edit: Whoops, thought I was still in the 'C' tag - but looking at the documentation, both Exception.backtrace and caller should hold arrays where the top of the call stack is first in the array. There look to be differences in how deep they go and some formatting.
编辑:哎呀,以为我还在'C'标签 - 但是看看文档,Exception.backtrace和调用者都应该保持数组,其中调用堆栈的顶部是数组中的第一个。它们的深度和格式存在差异。
#1
7
"Backtrace", "stack trace", "stack backtrace", etc. are names for the same thing. "Backtrace" specifically likely comes from the Linux tool of the same name. A stack trace doesn't refer to exceptions only - the current state of the program's call stack can always be displayed as a stack trace (which backtrace does, but so do many debugger views and tools). It's just helpful to output a stack trace during exceptions or errors.
“Backtrace”,“堆栈跟踪”,“堆栈回溯”等都是同一个名称的名称。 “Backtrace”特别可能来自同名的Linux工具。堆栈跟踪不仅仅涉及异常 - 程序调用堆栈的当前状态始终可以显示为堆栈跟踪(回溯可以显示,但许多调试器视图和工具也是如此)。在异常或错误期间输出堆栈跟踪很有帮助。
Edit: Whoops, thought I was still in the 'C' tag - but looking at the documentation, both Exception.backtrace and caller should hold arrays where the top of the call stack is first in the array. There look to be differences in how deep they go and some formatting.
编辑:哎呀,以为我还在'C'标签 - 但是看看文档,Exception.backtrace和调用者都应该保持数组,其中调用堆栈的顶部是数组中的第一个。它们的深度和格式存在差异。