Else without rescue is useless


#1

Dear All,

I am having the same warning message "else without rescue is useless" with this code :

class Account
attr_reader:name
attr_reader:balance
def initialize(name,balance=100)
@name = name
@balance = balance
end

public
def display_balance(pin_number)
puts pin_number == pin
"Balance: $#{@balance}."
else
puts "Access denied: incorrect PIN."
end
private
def pin
@pin = 1234
end

def pin_error
    return "Access denied: incorrect PIN."
end

end

Can someone explain what that means?

thx


4. Displaying the Balance
#2

class Account
attr_reader :name
attr_reader :balance

def initialize(name, balance=100)
  @name = name
  @balance = balance
end

private
def pin
   @pin = 1234 
end

private
def pin_error
    "Access denied: incorrect PIN."
end

public 
def display_balance(pin_number)
    if pin_number == pin
        puts "Balance: $#{@balance}."
    else
        puts pin_error    
    end
end

end


#3

thx rubysurfer52871 for the new code. What was the warning related to ?


#4

The warning was related to catching errors, which sadly isn't covered by codecademy.