Move your rescue.
def test
conn = adodb.connection
# Catches ALL possible exceptions from conn.open
conn.open rescue conn = nil
if conn.nil?
# add data to file
else
# add data to DB
end
end
Alternately,
def test
conn = adodb.connection
begin
conn.open
rescue
conn = nil
end
if conn.nil?
# add data to file
else
# add data to DB
end
end
Note that I’ve changed the order of your DB/file operations because
you can’t do a == or != test against nil (nil isn’t equal to
anything except nil).
-austin
– Austin Ziegler, austin@halostatue.ca on 2002.12.05 at 21.35.43
···
On Fri, 6 Dec 2002 11:30:47 +0900, Shannon Fang wrote:
On Fri, 6 Dec 2002 02:26:40 +0000 (GMT) > ahoward ahoward@fsl.noaa.gov wrote:
def test
begin
conn = adodb.connection
conn.open …
if conn != nil then
#add data to db
else
#add data to file
end
rescue DBError
conn = nil
resume next
end
end
i don’t quite understand this… the next WHAT? where is the
implied loop supposed to be?
The benefit of resume next is that it will catch all errors. Here,
I expect error to happen on the conn.open statement., so if error
happen, set conn=nil.