borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2009 Andrea Tincaniborder

AndreaVB | Forum | News | Downloads | Register | Help | Member List | Statistics | Search | PM | Profile

Print This Topic
Previous Topic (Interfacing to an external counter)Next Topic (Printer.?) New Topic New Poll Post Reply
AndreaVB Forum : VB General : Error code structure
Poster Message
Nomes
Level: Trainee

Registered: 14-05-2008
Posts: 1

icon Error code structure

I'm new to VB6 so if i sound LD it comes with us new guys.
I'm starting a database using VB6 and Access .

Does anybody have a complete error handling structure that can get me started. Or at least basic one?

Thanks  

14-05-2008 at 06:39 PM
View Profile Send Email to User Show All Posts | Quote Reply
stickleprojects
Level: Moderator


Registered: 09-09-2002
Posts: 1052
icon Re: Error code structure

HI
VB6 doesn't lend itself well to shrink wrapped error-handling, but I follow this structure:

EVERY function/proc (routine) has an error handler that raises the error (and appends the routine's name to the source) or shows it.
If the routine will be at the top of a call stack (ie. is an event), then show the error.
Show the errors using a central ShowError routine, that copies the err object and displays a pretty form with an english text, the call stack, allows email to support, etc.

I use MZTools' excellent error template to insert an error handler into the existing proc (hot-key ctrl-shift-E) then comment out the show/raise line as applicable.

example:

function mythingy (a, b, c) as boolean
on error goto errh

' default return value

' check params
if a<b then goto exith
if c>b then goto exith

'do some code here
' never exit the middle of a routine, always goto the exith

mythingy = true
exith:
on error goto 0
' cleanup, error handling is off to stop looping on errh if i put a resume_next in later on
exit function
errh:
  err.raise err.number, err.source & ",module1.bas:mythingy", err.description
' ShowError err, "module1.bas:mythingy","Creating invoice"
end function


I use functions rather than procs and return Success values just before the function ends. I see very little reason for fire-and-forget routines.

On top of this I add specific implementation for errors as required (ie. overwrite file prompts, readonly folders, etc.).

My style is defensive coding and I tend to assume that the calling programmer is an idiot who will not have checked the parameters before passing them in (ie. recordsets not open, objects nothing, etc).

NOTE:
This is just my structure and there are thousands of articles on different schemes. For example, I don't use asserts and never raise an error for an invalid argument.

Hope that's clear
Kieron


[Edited by stickleprojects on 15-05-2008 at 04:40 AM GMT]

____________________________
Build it better, faster, quicker, easier.. then fix it (non-offical MS mission statement)

15-05-2008 at 04:36 AM
View Profile Send Email to User Show All Posts | Quote Reply
AndreaVB Forum : VB General : Error code structure
Previous Topic (Interfacing to an external counter)Next Topic (Printer.?) New Topic New Poll Post Reply
Surf To:


Not Logged In? Username: Password: Lost your password?
Partners: Download Actual Software | Free Software Download
borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2009 Andrea Tincaniborder