Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does ruby's rb_raise stop the execution of the c function calling it?

Tags:

c

ruby

raise

If you write a ruby method as a function in C that uses rb_raise, the part of the function after the call will not get excecuted and the program will stop and you will think that rb_raise used exit(). But if you rescue the exception in ruby, like:

begin
  method_that_raises_an_exception
rescue
end
puts 'You wil still get here.'

The ruby code will go on, but your function will stop excecuting. How does rb_raise make this happen?

like image 260
Adrian Avatar asked Mar 29 '10 03:03

Adrian


1 Answers

Presumably it uses setjmp (before the method is called) and longjmp (in rb_raise).

like image 158
caf Avatar answered Nov 04 '22 03:11

caf