rescuing a function

  • Thread starter Courtland Allen
  • Start date
C

Courtland Allen

[Note: parts of this message were removed to make it a legal post.]

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
 
D

Dhruva Sagar

[Note: parts of this message were removed to make it a legal post.]

Are you sure that you don't have *args in your code instead of just args ?
In case of *args the warning makes sense...
 
J

Jeremy Bopp

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
 
C

Courtland Allen

[Note: parts of this message were removed to make it a legal post.]

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

Dhruva Sagar

[Note: parts of this message were removed to make it a legal post.]

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

Robert Klemme

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top