2013-11-28 45 views
0

我同意按下列紅寶石不會產生異常的3

$: << File.expand_path(File.dirname(__FILE__) + "/../../config") 
$: << File.expand_path(File.dirname(__FILE__) + "/../../lib") 

require 'activerecord-sqlserver-adapter' 
require 'sa.gw.library' 
require 'sa.gw.lib.connection_manager' 

#connecting to sqlserver test 
@app_config = YAML.load_file("#{File.dirname(__FILE__)}/../../config/sa.gw.c.victim.yml") 
connection_manager = ConnectionManager.new(@app_config["tpaldb"]) #H 

begin 
    sql = "exec spTPal_Vic_GetDeviceStateByIMEI '000000000000000'" 
    result = connection_manager.execute_sproc(sql) 
      result.each {|r| 

      puts 'hello'   
      }    
    connection_manager.connection.close() 
    rescue => e 
     puts "An error occurred detail: #{e.message}" 

    end 

我執行使用的Aptana Studio的3.這個程序這個簡單的代碼還算什麼我有經驗的是,如果存儲過程不讓用戶知道,那麼函數會自動終止。 我想要一個機制是知道過程不存在於表單消息或異常中。

堆棧跟蹤是在以下

["c:/Ruby193/lib/ruby/gems/1.9.1/gems/activerecord-sqlserver-adapter-3.2.12/lib/active_record/connection_adapters/sqlserver/database_statements.rb:416:in `each'", "c:/Ruby193/lib/ruby/gems/1.9.1/gems/activerecord-sqlserver-adapter-3.2.12/lib/active_record/connection_adapters/sqlserver/database_statements.rb:416:in `handle_to_names_and_values_dblib'", "c:/Ruby193/lib/ruby/gems/1.9.1/gems/activerecord-sqlserver-adapter-3.2.12/lib/active_record/connection_adapters/sqlserver/database_statements.rb:405:in `handle_to_names_and_values'", "c:/Ruby193/lib/ruby/gems/1.9.1/gems/activerecord-sqlserver-adapter-3.2.12/lib/active_record/connection_adapters/sqlserver/database_statements.rb:377:in `_raw_select'", "c:/Ruby193/lib/ruby/gems/1.9.1/gems/activerecord-sqlserver-adapter-3.2.12/lib/active_record/connection_adapters/sqlserver/database_statements.rb:371:in `block in raw_select'", "c:/Ruby193/lib/ruby/gems/1.9.1/gems/activerecord-3.2.12/lib/active_record/connection_adapters/abstract_adapter.rb:280:in `block in log'", "c:/Ruby193/lib/ruby/gems/1.9.1/gems/activesupport-3.2.12/lib/active_support/notifications/instrumenter.rb:20:in `instrument'", "c:/Ruby193/lib/ruby/gems/1.9.1/gems/activerecord-3.2.12/lib/active_record/connection_adapters/abstract_adapter.rb:275:in `log'", "c:/Ruby193/lib/ruby/gems/1.9.1/gems/activerecord-sqlserver-adapter-3.2.12/lib/active_record/connection_adapters/sqlserver/database_statements.rb:371:in `raw_select'", "c:/Ruby193/lib/ruby/gems/1.9.1/gems/activerecord-sqlserver-adapter-3.2.12/lib/active_record/connection_adapters/sqlserver/database_statements.rb:354:in `do_exec_query'", "c:/Ruby193/lib/ruby/gems/1.9.1/gems/activerecord-sqlserver-adapter-3.2.12/lib/active_record/connection_adapters/sqlserver/database_statements.rb:24:in `exec_query'", "c:/Ruby193/lib/ruby/gems/1.9.1/gems/activerecord-sqlserver-adapter-3.2.12/lib/active_record/connection_adapters/sqlserver/database_statements.rb:297:in `select'", "c:/Ruby193/lib/ruby/gems/1.9.1/gems/activerecord-3.2.12/lib/active_record/connection_adapters/abstract/database_statements.rb:18:in `select_all'", "c:/Ruby193/lib/ruby/gems/1.9.1/gems/activerecord-3.2.12/lib/active_record/connection_adapters/abstract/query_cache.rb:63:in `select_all'", "J:/SecureAlert_SVN/2.0.5 (Chilli)/lib/sa.gw.lib.connection_manager.rb:27:in `execute_sproc'", "J:/SecureAlert_SVN/2.0.5 (Chilli)/app/controllers/publisher_test.rb:16:in `<main>'"] 
+0

如果該過程不存在,應該提出什麼樣的錯誤?你沒有拯救任何東西,所以它不知道你想要拯救什麼。 '救援例外=>電子'應該讓你開始。但是你可能不想拯救那個特定的(所有的父母)異常。找到一個最接近應該獲救的東西。 – vgoff

+0

奇怪!當我調試Sql Server類中的代碼時,它顯示了我的錯誤。當我調試它並逐步完成代碼時,它會靜靜地終止,當我運行應用程序時,它又向我顯示了錯誤。 –

+0

你應該顯示堆棧跟蹤,然後解釋你的問題。 – vgoff

回答

0

在Ruby中,默認救出例外將是StandardError。您在這裏顯示的內容並不顯示出現了什麼錯誤,或者可能是從SQL而不是從Ruby提出的。

然後,您正在挽救StandardError,因爲您沒有指定要嘗試解救的異常,而且確實可能​​是錯誤的。