Send Email If Agent Fails

How can I add function to agent to email me if the agent fails?The agent is called by another agent during course enrollment. It simply counts number of students that enrolled in a particular class when ever they hit submit button.

I wanted the agent to send email when ever it fails to run. Please help!

Here is the code below:

Sub Initialize

On Error Goto ErrorHandler

Dim boxType As Long

'Messagebox “Increase Number of student signup”

Dim session As New NotesSession

Dim db As NotesDatabase

Dim view As NotesView

Dim doc As NotesDocument

Dim dc As NotesDocumentCollection

Dim key1 As NotesItem

Dim item As NotesItem

Dim keyString As String

Dim SignUp As Integer

Dim Student_Signup As Integer

Dim ClassMaximum As Integer

Set db = Session.CurrentDatabase

Dim location As String

Set thisAgent = session.CurrentAgent

keyString = session.GetEnvironmentString( “caCourseNumber” )

’ the view contains class announcement

Set view = db.GetView(“(ICClassMaxi)”)

Set dc = view.GetAllDocumentsByKey( keyString , False)

Set doc = dc.GetFirstDocument

If doc Is Nothing Then

End If

'If the number of students signed-up is equal to maximum allowed for class then do not continue

If doc.Student_Signup(0) = doc.ClassMaximum(0) Then

Continue = False

Else

Do Until doc Is Nothing

'Msgbox doc.Student_SignUp(0),0 , “Currently Signup”

SignUp = doc.Student_Signup(0)

SignUp = SignUp + 1

Set item = doc.ReplaceItemValue(“Student_Signup”, SignUp)

Call doc.Save(False, True)

'Msgbox doc.Student_SignUp(0), 0 , “Plus You”

Set doc= dc.GetNextDocument(doc)

Loop

End If

Done:

Exit Sub

ErrorHandler:

Select Case Err

Case Else

Msgbox "Error " & Cstr(Err) & " in " & thisAgent.Name & " on line " & Cstr(Erl) & ": "& Error

Resume Done

End Select

End Sub