From: Matsuo Hisanori Date: 1999-12-22T19:07:53+09:00 Subject: [ruby-list:19843] PostgreSQL 用拡張ライブラリの例外 松尾です。 「PostgreSQL用拡張ライブラリ」を使っていて、分からないところがあるので 教えてください。execが失敗したときの例外をrescueできないのですが、どう すれば良いでしょうか? 環境とサンプルコード、結果は以下の通りです。よろしくお願いします。 <環境> TurboLinux 4.2 PostgreSQL 6.5.2 on i586-pc-linux-gnu, compiled by gcc egcs-2.91.60 ruby 1.4.2 (1999-09-18) [i586-linux] PostgreSQL用拡張ライブラリ version 0.5.3 <コード name="p.rb"> require "postgres" connection = PGconn.connect("localhost", 5432, "", "", "") #connection.exec("drop table testtable;") connection.exec("create table testtable (id integer not null,primary key (id));") (0..2).each{|i| connection.exec("insert into testtable (id) values (#{i});") p "inserted #{i}" } begin connection.exec("insert into testtable (id) values (1);") p "inserted #{1}" rescue p "rescued" end <結果> $ ruby p.rb NOTICE: CREATE TABLE/PRIMARY KEY will create implicit index 'testtable_pkey' for table 'testtable' "inserted 0" "inserted 1" "inserted 2" p.rb:14:in `exec': server fatal error. Please report to your db administrator (PGError) from p.rb:14 $ -- # 冬休みはrdbcで遊ばさせて頂く予定です。