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

···

--
*Courtland Allen*

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 Sagar.

On Thu, Oct 7, 2010 at 07:44, Courtland Allen <courtlandallen@gmail.com>wrote:

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

--
*Courtland Allen*

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

···

On 10/06/2010 09:44 PM, Dhruva Sagar 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...

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 Wed, Oct 6, 2010 at 8:39 PM, Jeremy Bopp <jeremy@bopp.net> wrote:

On 10/06/2010 09:44 PM, Dhruva Sagar 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

--
*Courtland Allen*

Interesting...yea I didn't think of that

···

--
Thanks & Regards,
Dhruva Sagar.

On Thu, Oct 7, 2010 at 09:09, Jeremy Bopp <jeremy@bopp.net> wrote:

On 10/06/2010 09:44 PM, Dhruva Sagar 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

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

Kind regards

robert

···

On Thu, Oct 7, 2010 at 6:00 AM, Courtland Allen <courtlandallen@gmail.com> 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.

--
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/