红宝石 |线程回溯函数
Thread#backtrace() : backtrace()是一个 Thread 类方法,它返回目标线程的当前回溯。
Syntax: Thread.backtrace()
Parameter: Thread values
Return: the current backtrace of the target thread.
示例 #1:
# Ruby code for Thread.backtrace() method
# declaring Thread
a = Thread.new { print "a"; Thread.stop; print "c" }
# backtrace form
puts "Thread a backtrace() form : #{a.backtrace()}\n\n"
输出 :
Thread a backtrace() form : []
示例 #2:
# Ruby code for Thread.backtrace() method
# declaring Thread
a = Thread.new { puts "HI! I am learning to code"}
# backtrace form
puts "Thread a backtrace() form : #{a.backtrace()}\n\n"
输出 :
Thread a backtrace() form : []
HI! I am learning to code