cumbersome coding style (1 Viewer)

gemma-the-husky

Super Moderator
Staff member
Local time
Today, 02:20
Joined
Sep 12, 2006
Messages
15,656
I can't offhand think of an example of this, but from time to time, I want to do something, and carryon whether or not I got a run time error - but I can't just use an onerrror resume next, because the error will need some action.

so I end with this sort of thing


Code:
...
     on error goto failed
     execute process that might error
     goto continuepoint

failed:
     cleanup after error
     resume continuepoint

continuepoint:
      carry on


is there an easier way to do this. would try .. .catch be a better way of managing this sort of thing? I have never really looked at try .. catch in detail.
 

CJ_London

Super Moderator
Staff member
Local time
Today, 02:20
Joined
Feb 19, 2013
Messages
16,612
I sometimes use this when some in line correction can be done

Code:
 on error resume next
 [I]line where error may occur[/I]
 select case err.number
   case...
   ...
 end select
 on error goto 0
 ...
 ...

or

Code:
 on error resume next
 [I]line where error may occur[/I]
 if err.number<>0 then
   ...
   ...
 end if
 on error goto 0
 ...
 ...
 

vbaInet

AWF VIP
Local time
Today, 02:20
Joined
Jan 22, 2010
Messages
26,374
Similar to CJ's:
Code:
...
[COLOR="Blue"]     on error resume next[/COLOR]
     execute process that might error
[COLOR="blue"]     on error goto continuepoint[/COLOR]
     carry on with other code

failed:
     exit sub/function

continuepoint:
     handle other errors
     cleanup after error
     resume failed
 

JLCantara

Registered User.
Local time
Yesterday, 18:20
Joined
Jul 22, 2012
Messages
335
I can't offhand think of an example of this but you know that the error will need some action.
Are you a clairvoyant?:rolleyes:
 

Users who are viewing this thread

Top Bottom