# C API question: How to handle an error while freeing object

**URL:** <https://www.ruby-forum.com/t/c-api-question-how-to-handle-an-error-while-freeing-object/121187>\
**Category:** Ruby\
**Created:** [November 25, 2007, 1:40am UTC](https://www.ruby-forum.com/t/c-api-question-how-to-handle-an-error-while-freeing-object/121187 "2007-11-25T01:40:30Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![timhunter](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/71e660/32.png) [@timhunter](https://www.ruby-forum.com/u/timhunter)\
**Post date:** [November 25, 2007, 1:40am UTC](https://www.ruby-forum.com/t/c-api-question-how-to-handle-an-error-while-freeing-object/121187/1 "2007-11-25T01:40:30Z")

</div>

This is a C API question.

What’s the recommended way to handle an error that occurs while  
executing the free function that gets called from GC? (That is, the  
function pointed to by the 3rd argument to Data\_Wrap\_Struct?)

I have a free function that needs to delete one or more temporary files.  
If an error occurs while deleting one of these files, what should I do?

I’m pretty sure that calling rb\_raise is not the right thing.
