While the basic error-handling concepts are the same, errors within an ActiveX server class have to be handled slightly differently than errors in a client application. Some of the important differences include:
Don't display the error
Unlike a client application, in which you might display a message box to the user detailing the problem, you should remember that with a server-side application, there might be no one there to click OK! Instead, you should write an entry into an event log. (Section 6.4 details how to write an event log.) If you have a large application that already has many MsgBox calls, and you don't want to spend ages rewriting this code, simply go to the project properties dialog and select the Unattended Execution option. This forces all MsgBox calls to be written to an event log.
Once you've logged the error in your server class, you need some way of informing the user that an error occurred. The simplest method of doing this is to raise an error using the Err.Raise method. This error will be picked up by the client's error handler, and the relevant message displayed. This simple client and server code demonstrates the Err.Raise method:
Private Sub Command3_Click() On Error GoTo Command3_Err Dim oTest As TestErrors.DoStuff Set oTest = New TestErrors.DoStuff oTest.SomeStuff Set oTest = Nothing Command3_Err: MsgBox Err.Description & vbCrLf & Err.Number & _ vbCrLf & Err.Source End Sub