# How to access manipulate on Exception type object of ruby in C?

**URL:** <https://rubytalk.org/t/how-to-access-manipulate-on-exception-type-object-of-ruby-in-c/63594>\
**Category:** ruby-talk\
**Created:** [14 September 2011 14:00 UTC](https://rubytalk.org/t/how-to-access-manipulate-on-exception-type-object-of-ruby-in-c/63594 "2011-09-14T14:00:10Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Balasaheb\_S](https://avatars.discourse-cdn.com/v4/letter/b/97f17d/32.png) [@Balasaheb\_S](https://rubytalk.org/u/Balasaheb_S)\
**Post date:** [14 September 2011 14:00 UTC](https://rubytalk.org/t/how-to-access-manipulate-on-exception-type-object-of-ruby-in-c/63594/1 "2011-09-14T14:00:10Z")

</div>

Hi, Im working on Ruby C extension, FOllowing is the code of my myRuby.c  
file containing implementation of some function which are accessed from  
ruby script.  
myRuby.c:  
static VALUE myMethod(VALUE self, VALUE exc)  
{  
&nbsp;&nbsp;&nbsp;int a = TYPE(exc);  
&nbsp;&nbsp;&nbsp;printf(" %d ", a );  
&nbsp;&nbsp;&nbsp;// Some manipulation on exc i.e. Access its attributes  
}  
void Init\_myRuby()  
{  
&nbsp;&nbsp;&nbsp;&nbsp;VALUE mRuby = rb\_define\_module("myRuby");  
&nbsp;&nbsp;&nbsp;&nbsp;VALUE mException = rb\_define\_class\_under(mRuby, "Exception",  
rb\_eRuntimeError);  
&nbsp;&nbsp;&nbsp;&nbsp;rb\_define\_singleton\_method(mRuby, "myMethod", myMethod, 4);  
}

AND following id the code from client.rb which invokes the function from  
above myRuby.c file.  
client.rb:  
require 'myRuby'  
def raiseExc()  
&nbsp;&nbsp;exception = myRuby::Exception.new("status","lasterror","function()",  
&nbsp;&nbsp;&nbsp;"Calling some")  
&nbsp;&nbsp;myRuby::myMethod(exception, "Exception message: %s, Exception object  
&nbsp;&nbsp;%d", "Hi from Exception", 100)  
end

raiseExc()

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).
