Wrox Home  
Search P2P Archive for: Go

  Return to Index  

pro_vb thread: Lhotka and error handling approaches


Message #1 by Matt Walsh <matthew.walsh@n...> on Tue, 13 Feb 2001 11:50:33 -0500
I use the following approach:

1.	When I need to throw an error from within a component, I raise the
error using a custom error number, trap the error at the end of the
procedure so I can log it to a file, then re-raise the error to the calling
application.  Here is an example from one of our UI-Centric components
(non-MTS) of a function with error handling.  This function is a member of
the "User" object and validates whether or not the user has access to a
resource:

Public Function ValidateAccess(rsResourceID As String, Optional ByVal
vsSecurityID As String) As Boolean

    Const SOURCENAME As String = CLASS_NAME & "::ValidateAccess()"
'CLASS_NAME = "User"
    Dim sSecID As String
    Dim oPersist As UserPersist
    Dim bReturn As Boolean
    
On Error GoTo ERROR_TRAP

    '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    'ERR_SECURITY_ID_REQUIRED is a constant for a custom error number.
    'If the error is raise, we go directly to ERROR_TRAP
    If (vsSecurityID = "" And SecurityID = "") Then Err.Raise
ERR_SECURITY_ID_REQUIRED, CLASS_NAME
    
    sSecID = SecurityID
    If Len(sSecID) = 0 Then sSecID = vsSecurityID

    Set oPersist = CreateObject(USER_PERSIST, APP_SERVER)
    bReturn = oPersist.ValidateUserAccess(rsResourceID, sSecID)
    
ERROR_TRAP:
    
    Set oPersist = Nothing
    
    If Err.Number <> TGI_SUCCESS Then	'TGI_SUCCESS = 0
        Dim lErrLine As Long
        Dim lErrNumber As Long
        Dim strErrSource As String
        Dim strErrDescription As String
    
        'Preserve Error Information
        lErrNumber = Err.Number
        lErrLine = Erl
        strErrSource = Err.Source
        strErrDescription = Err.Description
    
        '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    	  'HandleError is a member function of a utility dll that gets the
	  'custom error description from a file and logs the error to a
 	  'log file.
        Call HandleError(lErrNumber, strErrDescription, SOURCENAME,
App.EXEName, App.Path, _
                         lErrLine, CLASS_NAME, False, strErrSource)
        Err.Raise lErrNumber, strErrSource, strErrDescription
    End If
    
    ValidateAccess = bReturn
    
End Function

Peter Conrey
Sr. Programmer/Analyst
Transaction Graphics, Inc.
(xxx) xxx-xxxx


-----Original Message-----
From: Matt Walsh [mailto:matthew.walsh@n...]
Sent: Tuesday, February 13, 2001 10:51 AM
To: professional vb
Subject: [pro_vb] Lhotka and error handling approaches


For those applying Lhotka's object component model;
==================================================

Would those of you whom have adopted this model, please offer some advice on
the methods you use to raise errors and present them to the UI?

Have you adopted a 'main' error routine in the UI? and always pass the
errors through the rule classes to the UI? or maybe a procedure by procedure
trap?

Consider please the concurrency case (discussed in an earlier thread);
having decided upon the "Someone else has modified the record" response
(with a refresh), how best should we go about the error raising path and
presentation?

Your input is very much appreciated.   :)

Thx 
(any code snipets would be much appreciated)


  Return to Index