Wrox Home  
Search P2P Archive for: Go

  Return to Index  

pro_vb thread: Error trapping routine


Message #1 by Talon Wolles <ta_iwo@y...> on Sat, 19 Oct 2002 17:23:46 -0700 (PDT)
Talon,

Unfortunately, you really have to have error handling code in every routine
where you expect an error. It's the only safe way to do it.

What we do here is run a precompiler which adds error handling (line
numbers, reports arguments sent to subroutines etc) to every routine, soa
routine that started off as

Private Sub ProcDir(xvFiles)
      SortShell xvFiles
      Dim svIndex
      For svIndex = 0 To UBound(xvFiles)
          ProcFile xvFiles(svIndex)
      Next
End Sub

ends up as:

      Private Sub ProcDir(xvFiles)
          WriteLog "Entering Private Sub ProcDir", LOG2_VERBOSE
          On Error GoTo Handle_Error
'      ----------------------------------------------------------------
If Not IsArray(xvFiles) Then WriteLog "xvFiles = " & xvFiles, LOG2_VERBOSE
WriteLog "Line 208", LOG1_DEBUG
208       SortShell xvFiles
          Dim svIndex
WriteLog "Line 209", LOG1_DEBUG
209       For svIndex = 0 To UBound(xvFiles)
WriteLog "Line 210", LOG1_DEBUG
210           ProcFile xvFiles(svIndex)
WriteLog "Line 211", LOG1_DEBUG
211       Next
      '----------------------------------------------------------------
      WriteLog "Exiting  Private Sub ProcDir", LOG2_VERBOSE
      Exit Sub
Handle_Error:
          Dump "From subroutine 'Private Sub ProcDir'"
      End Sub

By setting a registry entry, we can determine what level of information is
sent back to us (our software runs all over the world, and all log files are
ftp'd to us every 30 minutes)

The dump routine tells us what the error is, what line number in what
routine it occurred, what else is running on the computer, registry settings
etc

We don't normally ship with the line numbers written to the log, but in some
awkward cases we use this to tell us exactly what is going on.

If we were opening a file where we might expect it to be locked, we would
write it as

On Error Goto FileLocked
Open "text.txt" for input as svFH
On Error Goto 0

You have to handle and unhandle errors immediately before/after the dodgy
line

(Our precompiler changes the 'On Error Goto 0' to 'On Error GoTo
Handle_Error')

It's the only way to catch all errors

Ian

--------------------------------------------
Ian Bambury
eCommerce Project Manager
JAS Worldwide

ibambury@j...
www.jasww.com
--------------------------------------------



----- Original Message -----
From: "Talon Wolles" <ta_iwo@y...>
To: "professional vb" <pro_vb@p...>
Sent: Tuesday, October 22, 2002 1:24 AM
Subject: [pro_vb] Re: Error trapping routine


> Ian, thanks for yor effort. You see, what I want is a
> general code that any module can refer to. Like a
> public function or sub. The piece you wrote will have
> to appear in EVERY module that a file is opened which
> I don't want.
> For example, if I have a line like this:
> .
> .
> Dim db as database
> Dim ws  as workspace
> .
> set db=ws.opendatabase("mydata.mdb",true,true)
> .
>
>
> An attempt to open this file exclusively, if already
> opened by another user, should generate database lock
> error. Then I should have a general routine to trap
> this error.
>
> The rountine should be some thing like:
>
> .
> .
> select case err.number
>
> case 100  (hypothetical)
>
>  msgbox "Attempt to open a locked file..."
> .
> .
> case 110
>   .
>   .
>
> end select
>
> To write the routine is not my problem but where will
> I place the routine  or how will I write it in such a
> way that any error will lookup at the routine.
>
> Please anybody could help.
>
>
> -Talon
>
> to 



  Return to Index