# Catching runtime exceptions from callbacks

**URL:** <https://www.ruby-forum.com/t/catching-runtime-exceptions-from-callbacks/135495>\
**Category:** Ruby\
**Created:** [April 22, 2008, 6:01pm UTC](https://www.ruby-forum.com/t/catching-runtime-exceptions-from-callbacks/135495 "2008-04-22T18:01:41Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [April 22, 2008, 6:01pm UTC](https://www.ruby-forum.com/t/catching-runtime-exceptions-from-callbacks/135495/1 "2008-04-22T18:01:41Z")

</div>

Hello,

I am currently integrating Ruby (1.8.6) inside an application. Until  
now, I had no impossible problem although the API documentation is a  
bit poor.

I use rb\_load\_protect to load a startup script file that contains some  
callbacks like this :  
Events.onChar { |char|  
print(“char:#{char}”);  
}  
If there is an error while loading the file, I can catch it and get  
the backtrace and everything I want because it’s inside protect(). But  
if I use for example raise inside the callback, my program stops due  
to a C++ runtime exception (here it’s not inside protect() anymore  
because rb\_load\_protect returns after the file has been loaded).

I don’t know if it is possible but I would like to be able to also  
catch RuntimeError (and all others) in my C++ code.  
Thanks.

Remi Gillig.
