[英]Ruby xml rpc error handling
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. 如果服务器未在localhost:8080上运行,则出现Errno :: ECONNREFUSED错误。
I want to display an error message to user, how can a handle this error? 我想向用户显示错误消息,如何处理该错误?
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.