我想出來的unidecoder寶石和它給我的問題有一些字符串:問題捕unidecoder例外
require 'unidecoder'
str = "\u00A3"
str.to_ascii
#:(C:/Ruby193/lib/ruby/gems/1.9.1 /gems/unidecoder-1.1.1/lib/unidecoder/data/x00.yml): 從C:/Ruby193/lib/ruby/1.9解析報價d標量行 2列3 時發現未知轉義字符。 1/psych.rb:203:在
parse' from C:/Ruby193/lib/ruby/1.9.1/psych.rb:203:in
parse_stream' from C:/Ruby193/lib/ruby/1.9.1/psych.rb:151:在parse' from C:/Ruby193/lib/ruby/1.9.1/psych.rb:127:in
從C:/ Ruby193/lib/r加載' uby/1.9.1/psych.rb:297:在block in load_file' from C:/Ruby193/lib/ruby/1.9.1/psych.rb:297:in
中打開' from C:/Ruby193/lib/ruby/1.9.1/psych.rb:297:load_file' from C:/Ruby193/lib/ruby/gems/1.9.1/gems/unidecoder-1.1.1/lib/unidecoder.rb:8:in
block' from C:/ Ruby193/lib /ruby/gems/1.9.1/gems/unidecoder-1.1.1/lib/unidecoder.rb:78:inyield' from C:/Ruby193/lib/ruby/gems/1.9.1/gems/unidecoder-1.1.1/lib/unidecoder.rb:78:in
默認' from C:/Ruby193/lib/ruby/gems/1.9.1/gems/unidecoder -1.1.1/lib/unidecoder.rb:78:在decode_char' from C:/Ruby193/lib/ruby/gems/1.9.1/gems/unidecoder-1.1.1/lib/unidecoder.rb:39:in
塊中解碼' from C:/Ruby193/lib/ruby/gems/1.9.1/gems/unidecoder-1.1.1/lib/unidecoder.rb :37:在gsub' from C:/Ruby193/lib/ruby/gems/1.9.1/gems/unidecoder-1.1.1/lib/unidecoder.rb:37:in
解碼 ' 從C:/Ruby193/lib/ruby/gems/1.9.1/gems/unidecoder-1.1.1/lib/unidecoder.rb:16:在to_ascii' from (irb):21 from C:/Ruby193/bin/irb:12:in
' >>
更糟的是,我不能這樣做捕獲錯誤:
foo = str.to_ascii rescue 'x'
有誰知道這裏發生了什麼?
什麼是您當前的系統'LOCALE'?關於救援:[救援條款沒有參數列表,參數默認爲StandardError](http://rubylearning.com/satishtalim/ruby_exceptions.html);它看起來像「unidecoder」引發了其他異常,但堆棧跟蹤似乎是不完整的(它應該顯示異常類型)。 – mudasobwa 2013-03-25 04:42:47
@mudasobwa - 我認爲這一定是它。我的印象是,沒有參數的救援抓住了一切。如果你想把它放在答案中,我會接受。 – pguardiario 2013-03-25 05:05:31