Zip Component, Email Component, Encryption Component ActiveX Control for Zip Compression .NET Components for ASP.NET
ActiveX and .NET Components for Zip Compression, Encryption, Email, XML, S/MIME, HTML Email, Character Encoding, Digital Certificates, FTP, and more ASP Email ActiveX Component

Index of Chilkat Blog Posts

November 26, 2007

ASP Pitfall: On Error Resume Next

When "On Error Resume Next" is used, you may be faced with seemingly inexplicable behavior. The ASP code below has a single error: the string passed to Server.CreateObject is incorrect and the mailman object is never created. When "On Error Resume Next" is present, the code runs and reports that the email is sent. (More explanation about why this occurs follows.)

In summary: If you are debugging ASP, make sure to remove "On Error Resume Next". It doesn’t make sense to hide the error when you’re looking for it..

Why does the code below run and report that the email was sent? The CreateObject fails and mailman is set to Nothing. Any attempt to dereference mailman causes an error, but it is suppressed and execution continues with the next line of code. Therefore, a line such as this:

success = mailman.UnlockComponent("30-day trial")

never runs, and success is never set. success remains unchanged, and because it was previously set to 1, it remains at that value. The "On Error Resume Next" made it seem like that mailman.UnlockComponent method was successfully called. The same applies to the call to mailman.SendEmail.

<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
success = 1
on error resume next
'  The mailman object is used for sending and receiving email.
<strong>set mailman = Server.CreateObject("Chilkat.DoesNotExist")   — ERROR HERE, mailman is Nothing</strong>
‘  Any string argument automatically begins the 30-day trial.
<strong>success = mailman.UnlockComponent("30-day trial")  — THIS ERROR IS SUPPRESSED, success retains its original value</strong>
If (success <> 1) Then
    Response.Write "Component unlock failed" & "<br>"
End If
‘  Set the SMTP server.
<strong>mailman.SmtpHost = ""  ERROR SUPPRESSED HERE.</strong>
‘  Create a new email object
set email = Server.CreateObject("Chilkat.Email2")
email.Subject = "This is a test"
email.Body = "This is a test"
email.From = "Chilkat Support <>"
email.AddTo "Admin",""
<strong>success = mailman.SendEmail(email) — THIS ERROR IS SUPPRESSED, success still equals 1.</strong>
If (success <> 1) Then
    Response.Write mailman.LastErrorText & "<br>"
    Response.Write "Mail Sent!" & "<br>"
End If

Privacy Statement. Copyright 2000-2011 Chilkat Software, Inc. All rights reserved.
Send feedback to

Components for Microsoft Windows XP, 2000, 2003 Server, Vista, Windows 7, and Windows 95/98/NT4.