Ruby: else without rescue is useless Ruby: else without rescue is useless ruby ruby

Ruby: else without rescue is useless


if condition  # …else  # …end

not

if condition  # …endelse  # …end


It looks like the else block is not part of an if statement. Am I correct in assuming you want it to provide an alternative path when if @@counter > 0 is false? If so, get rid of the end that's on the line above the else, e.g.:

if @@Counter > 0    # ... processing ...else    # ... alternative processing ...end


To clarify: else is the warning is intended as below:

def my_method  if rand >= 0.5    raise  endrescue  puts "ERROR!!!"else  puts "Cool"end

If you prematurely close the if statement, it's likely that the else will be interpreted as the else in the code above. So having an else statement without the rescue is useless, because you can simply write your method like this:

def my_method  if rand >= 0.5    raise  end  puts "Cool"end

Either rescue is executed, or else is executed, never both.