0

I have a model


class Car
  @@RPCServer = XMLRPC::Client.new("localhost", "/", 8080)

  def self.count
    @@RPCServer.call("cars.count")
  end
end

If server is not running on localhost:8080 I've got a Errno::ECONNREFUSED error.
I want to display an error message to user, how can a handle this error?

1 Answer 1

1

You need to trap the error in order to handle the exception in the way your application needs. The following code will trap this Exception. If you need to trap other exceptions then you can include multiple rescue clauses.

class Car
  @@RPCServer = XMLRPC::Client.new("localhost", "/", 8080)

  def self.count
    begin
      @@RPCServer.call("cars.count")
    rescue Errno::ECONNREFUSED
      # Do Appropriate handling here
    end
  end
end
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.