From: Paul Brannan Date: 2008-10-22T01:58:23+09:00 Subject: [ruby-core:19418] Re: rb_errinfo() vs rb_rubylevel_errinfo() On Wed, Oct 22, 2008 at 12:34:19AM +0900, SASADA Koichi wrote: > 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. Is this just an optimization that e and $! are the same place on the stack? Assigning to e does not change $!. > 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? Yes, it does, thank you. Two more: 1. Why do you choose to use a local variable to store errinfo in YARV? It was thread-local (global variable that is swapped when the thread is swapped) in 1.8. 2. On 1.8 it was possible to assign to $!, but this has been disabled on YARV. Is there a particular reason? Paul