From: David Naseby Date: 2002-12-06T11:43:29+09:00 Subject: Re: on error resume next >-----Original Message----- >From: Shannon Fang [mailto:xrfang@hotmail.com] > >> > I tried to do the following: (peudo-code) >> > >> > 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. > This thread seems so wrong on so many levels. Wishing for VB-like 'error handling' is.. well.. its quite beyond my comprehension. If you really want to achieve the implied behaviour of the piece of pseudo-code above, try: def test begin conn=adodb.connection conn.open ... rescue ADatabaseError conn = nil end if conn.nil? then #add data to file else #add data to db end ensure conn.Close unless conn.nil? end But I think you really have to ask yourself, will this give me a good system state if some random error can throw my (logging/ reporting/ whatever DB is supposed to hold) to file at any random moment? How do you later reconcile the DB and file? If this is supposed to be a program level switch, write a DoWhateverImDoingToStoreData class that can polymorphically write to file or database depending on a factory level switch, and pick it at runtime - to switch mid program as the result of an error seems like folly. YMMV David Naseby