# Error handling with command calls

**URL:** <https://www.ruby-forum.com/t/error-handling-with-command-calls/143024>\
**Category:** Ruby\
**Created:** [July 14, 2008, 4:40pm UTC](https://www.ruby-forum.com/t/error-handling-with-command-calls/143024 "2008-07-14T16:40:40Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![stefans](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/9d8465/32.png) [@stefans](https://www.ruby-forum.com/u/stefans)\
**Post date:** [July 14, 2008, 4:40pm UTC](https://www.ruby-forum.com/t/error-handling-with-command-calls/143024/1 "2008-07-14T16:40:40Z")

</div>

Hello,

I’m trying to rewrite a Bash shell script with Ruby.

`do_something`  
if $?.exitstatus != 0  
handle\_error  
end

`do_some_other_thing`  
if $?.exitstatus != 0  
handle\_error  
end

How can I avoid having to poll exitstatus after every command call? I’m  
looking for something to replace bash’s trap.

Stefan
