Rescuing a function

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

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…

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

Interesting…yea I didn’t think of that


Thanks & Regards,
Dhruva S…

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.

On Thu, Oct 7, 2010 at 6:00 AM, Courtland A.
[email protected] 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