# Catching exceptions from embedded ruby

**URL:** <https://www.ruby-forum.com/t/catching-exceptions-from-embedded-ruby/52427>\
**Category:** Ruby\
**Created:** [January 13, 2006, 11:55pm UTC](https://www.ruby-forum.com/t/catching-exceptions-from-embedded-ruby/52427 "2006-01-13T23:55:31Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![joe-dumoulin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9dc877/32.png) [@joe-dumoulin](https://www.ruby-forum.com/u/joe-dumoulin)\
**Post date:** [January 13, 2006, 11:55pm UTC](https://www.ruby-forum.com/t/catching-exceptions-from-embedded-ruby/52427/1 "2006-01-13T23:55:31Z")

</div>

I’m embedding Ruby in a C program. If the Ruby program throws an  
exception, I’d like to catch it and print out the error. How could I  
do that?

---

<div class="post-metadata">

**Author:** ![joe-dumoulin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9dc877/32.png) [@joe-dumoulin](https://www.ruby-forum.com/u/joe-dumoulin)\
**Post date:** [January 14, 2006, 12:16am UTC](https://www.ruby-forum.com/t/catching-exceptions-from-embedded-ruby/52427/2 "2006-01-14T00:16:39Z")

</div>

On 1/13/06, Joe Van D. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I’m embedding Ruby in a C program. If the Ruby program throws an  
> exception, I’d like to catch it and print out the error. How could I  
> do that?

I can protect the function that might return an exception (via  
rb\_protect), but how can I display the reason why the exception was  
thrown (hopefully along with a backtrace)?
