From: Shannon Fang Date: 2002-12-06T15:55:31+09:00 Subject: Re: on error resume next I can't express how I feel :( The code below is just ONE of its usage, something else in my mind is: begin # do whatever you want to do rescue Error A #fix error retry rescue Error B resume next rescue printe "I can't fix your error" end In the above, between begin ... rescue Error A, any possible Error can occur, if you don't have resume next mechanism, you need to wrap the begin end block around the place that the error may occur, multi times. Please do not misunderstand, and discuss "how to reconcile database and disk file". The following task is just a SAMPLE. In some critical tasks, you may want to ignore some trivial errors and continue. For example, if you run a web server, you don't want to find out in the morning that your server was shut down for 10 hours just because it can't write into the weblog file... Thanks! Shannon On Fri, 6 Dec 2002 11:43:29 +0900 David Naseby wrote: > >-----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