# Rescuing a function

**URL:** <https://www.ruby-forum.com/t/rescuing-a-function/196125>\
**Category:** Ruby\
**Created:** [October 7, 2010, 4:15am UTC](https://www.ruby-forum.com/t/rescuing-a-function/196125 "2010-10-07T04:15:18Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Courtland\_A](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/48db29/32.png) [@Courtland\_A](https://www.ruby-forum.com/u/Courtland_A)\
**Post date:** [October 7, 2010, 4:15am UTC](https://www.ruby-forum.com/t/rescuing-a-function/196125/1 "2010-10-07T04:15:18Z")

</div>

Hello,

I’ve normally handled exceptions by “rescuing functions” in roughly this  
manner:

def test\_function(args)  
puts “blah blah blah”  
rescue Exception=\>e  
puts “blah blah blah: #{args.inspect}”  
end

However, I’m using a new IDE now that’s giving me a warning about the  
reference to “args” in the rescue clause: “Local variable can be  
uninitialized.” I figured that’s impossible, since it’s a required  
argument  
to the function. Should I just ignore the warning, or am I actually  
doing  
something wrong? I suppose the alternative would be:

def test\_function(args)  
begin  
puts “blah blah blah”  
rescue Exception=\>e  
puts “blah blah blah: #{args.inspect}”  
end  
end

---

<div class="post-metadata">

**Author:** ![Courtland\_A](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/48db29/32.png) [@Courtland\_A](https://www.ruby-forum.com/u/Courtland_A)\
**Post date:** [October 7, 2010, 4:45am UTC](https://www.ruby-forum.com/t/rescuing-a-function/196125/2 "2010-10-07T04:45:09Z")

</div>

Are you sure that you don’t have \*args in your code instead of just args  
?  
In case of \*args the warning makes sense…

–  
Thanks & Regards,  
Dhruva S…

---

<div class="post-metadata">

**Author:** ![Courtland\_A](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/48db29/32.png) [@Courtland\_A](https://www.ruby-forum.com/u/Courtland_A)\
**Post date:** [October 7, 2010, 5:46am UTC](https://www.ruby-forum.com/t/rescuing-a-function/196125/3 "2010-10-07T05:46:00Z")

</div>

On 10/06/2010 09:44 PM, Dhruva S. wrote:

> Are you sure that you don’t have \*args in your code instead of just args ?  
> In case of \*args the warning makes sense…

Actually, \*args is certain to be initialized. If no arguments are  
passed to the method, args will be an empty array. If any arguments are  
passed, they will be elements of that array.

I think the warning from the IDE is bogus. What happens if you define a  
default value for args?

-Jeremy

---

<div class="post-metadata">

**Author:** ![Courtland\_A](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/48db29/32.png) [@Courtland\_A](https://www.ruby-forum.com/u/Courtland_A)\
**Post date:** [October 7, 2010, 6:38am UTC](https://www.ruby-forum.com/t/rescuing-a-function/196125/4 "2010-10-07T06:38:40Z")

</div>

Interesting…yea I didn’t think of that

–  
Thanks & Regards,  
Dhruva S…

---

<div class="post-metadata">

**Author:** ![Courtland\_A](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/48db29/32.png) [@Courtland\_A](https://www.ruby-forum.com/u/Courtland_A)\
**Post date:** [October 7, 2010, 6:01am UTC](https://www.ruby-forum.com/t/rescuing-a-function/196125/5 "2010-10-07T06:01:48Z")

</div>

Yep it still gives a warning when I define a default value for the  
argument,  
so it’s probably just a bug in the IDE.

---

<div class="post-metadata">

**Author:** ![Courtland\_A](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/48db29/32.png) [@Courtland\_A](https://www.ruby-forum.com/u/Courtland_A)\
**Post date:** [October 7, 2010, 12:55pm UTC](https://www.ruby-forum.com/t/rescuing-a-function/196125/6 "2010-10-07T12:55:35Z")

</div>

On Thu, Oct 7, 2010 at 6:00 AM, Courtland A.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Yep it still gives a warning when I define a default value for the argument,  
> so it’s probably just a bug in the IDE.

Yes, certainly. You could open a bug report. What IDE is it?

Kind regards

robert
