在RubyMotion中引发NSError
问题描述:
我编写的应用程序基本上只是http API的客户端。我试图重复使用Redis Search sample(DataParser
和JsonParser
)中的代码,但在API调用期间发生错误时,RubyMotion无法引发该错误。它尝试raise
错误指针中的第一个错误,它是NSError
和raise
预计Exception
祖先。在RubyMotion中引发NSError
RubyMotion项目中的HTTP错误如何处理?
我不使用BW :: HTTP,因为我发现它已被弃用。
收到的错误:
data_parser.rb:7:in `parse:': exception class/object expected (TypeError)
一个没有这样的代码:
class DataParser
def self.parse(url)
error_ptr = Pointer.new(:object)
data = NSData.alloc.initWithContentsOfURL(NSURL.URLWithString(url), options:NSDataReadingUncached, error:error_ptr)
unless data
NSLog error_ptr[0].inspect
raise error_ptr[0]
end
data
end
end
谢谢你的建议。不幸的是,当我按照指导(https://github.com/clayallsopp/AFMotion#install)安装AFMotion时,出现错误(无法找到AFMotion的规范)。你做什么不同于指南中的方式? – Mailo
尝试:gem install afmotion或将其添加到您的Gemfile – arashb31
这就是指南所说的,正如我所提到的,该指南不适用于我 – Mailo