Err.Description Property

Syntax

To set the property:

Err.Description = string

To return the property value:

string = Err.Description


string

Use: Required

Data Type: String

Any string expression.

Description

A read/write property containing a short string describing a runtime error.

Rules at a Glance

  • When a runtime error occurs, the Description property is automatically assigned the standard description of the error.

  • For application-defined errors, you must assign a string expression to the Description property or the error won't have an accompanying textual message.

  • You can override the standard description by assigning your own description to the Err object for both VB errors and application-defined errors.

Programming Tips and Gotchas

  • If an error occurs within a class module, an ActiveX DLL, or an EXE—regardless of whether it's running in or out of your application's process space—no error information from the component is available to your application unless you explicitly pass back an error code as part of the error-handling routine within the component. This is done using the Err.Raise method, which allows you to raise an error on the client, passing custom parameters for Number, Source, and Description.

  • If you raise an error with the Err.Raise method and don't set the Description property, the Description property is automatically set to "Application Defined or Object Defined Error."

  • You can also pass the Err.Description to a logging device such as a log file in Windows 95 or the application log in Windows NT by using the App.LogEvent method, as the following code fragment demonstrates:

    EmployeesAdd_Err:
    App.LogEvent "EmployeesAdd" & "; " & _
                 Err.Description, vbLogEventTypeError

  • The best way to set the Description property for your own application-defined errors is to use the named description argument with the Raise method, as the following code shows:

    Sub TestErr()
    
    On Error GoTo TestErr_Err
    
       Err.Raise Number := 65444, _
                 Description := "Meaningful Error Description"
        
    TestErr_Exit:
       Exit Sub
    
    TestErr_Err:
       MsgBox Err.Description
       Resume TestErr_Exit
    
    End Sub

See Also

Err.Object, Err.Number, Err.Raise Method
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.16.21.237