From: SASADA Koichi Date: 2008-10-22T00:34:19+09:00 Subject: [ruby-core:19411] Re: rb_errinfo() vs rb_rubylevel_errinfo() Hi, Paul Brannan wrote: > What is the difference between these two functions? > > When is rb_rubylevel_errinfo() intended to be used? (or is it? it is > exported, but not declared in a header) > > Why the two different places to store errinfo (in the thread object and > in the cfp)? def m # (3) end begin raise # (2) rescue => e # (1) m() end On (1), we can access $! with variable "e". $! and "e" is same place on VM stack (not cfp, but VM stack witch is accessed by dfp). This is means that $! is ruby level "local variable". rb_rubylevel_errinfo() returns that contents. On (2), there is no local variable to store error information throwed by "raise" method. To propagate errinfo, rb_thread_t#errinfo is used. "raise" (rb_raise) stores errinfo into rb_thread_t structure of current method, and bring it to VM exception procedure. VM receives errinfo and store it into local variable which I described above if corresponding "rescue" clause (or ensure) is there. On (3), $! is also returns contents of "e" variable in (1). VM backwinds cfp and looking for exception handling frame. If no exception handling are there, only "nil" was returned. Is this answer your question? -- // SASADA Koichi at atdot dot net