pulpfiction Posted March 30, 2006 Share Posted March 30, 2006 Whats wrong with the Exception Handling,getting the following errorError Type:Microsoft VBScript compilation (0x800A0400)Expected statement/test.asp, line 26End TryThis is the code <html><body><% Dim objMessage,objConfig,Flds Set objMessage = createobject("cdo.message") Set objConfig = createobject("cdo.configuration") Set Flds = objConfig.Fields Flds.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2'Flds.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "....." Flds.update Set objMessage.Configuration = objConfig Try objMessage.TextBody = "this is a test mail" objMessage.To = "......" objMessage.From = "......" objMessage.Subject = "Test mail" objMessage.TextBody = "test mail" objMessage.fields.update objMessage.Send Catch respones.write("error") End Try 'Set objMessage = Nothing 'Set objConfig = Nothing 'Response.Write("success") ' response.Write("failure") %></body></html> I have commented the fld.item so that it throws an exception. Thank you. Link to comment Share on other sites More sharing options...
pulpfiction Posted March 30, 2006 Author Share Posted March 30, 2006 If i am not worng, is it true vbscript doesnt have exception handling (the Try.. Catch thing). Link to comment Share on other sites More sharing options...
Yahweh Posted March 30, 2006 Share Posted March 30, 2006 Whats wrong with the Exception Handling,getting the following errorError Type:Microsoft VBScript compilation (0x800A0400)Expected statement/test.asp, line 26End TryThis is the code<html><body><% Dim objMessage,objConfig,Flds Set objMessage = createobject("cdo.message") Set objConfig = createobject("cdo.configuration") Set Flds = objConfig.Fields Flds.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2'Flds.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "....." Flds.update Set objMessage.Configuration = objConfig Try objMessage.TextBody = "this is a test mail" objMessage.To = "......" objMessage.From = "......" objMessage.Subject = "Test mail" objMessage.TextBody = "test mail" objMessage.fields.update objMessage.Send Catch respones.write("error") End Try 'Set objMessage = Nothing 'Set objConfig = Nothing 'Response.Write("success") ' response.Write("failure") %></body></html> I have commented the fld.item so that it throws an exception. Thank you. <{POST_SNAPBACK}> There is no Try/Catch in VBScript, but there is one in JScript. Also, you'll generate a syntax error by using respones.write("error") instead of response.write("error"). Generally, when catching errors in ASP, you can use On Error Resume Next and use if err.number then ... end if to troubleshoot after any line which you suspect could cause a proble, or use On Error Goto 0 to stop the error right away.However, if you want to send emails, use this code:<% Option Explicit %><html><body><%Dim objCDOSet objCDO = Server.CreateObject("CDONTS.NewMail")objCDO.To = "sender@someone.com"objCDO.From = "reciever@someone.com"Dim txtSubjecttxtSubject = "Your message should go right here." objCDO.Subject = "Your subject should go here."objCDO.Body = txtSubjectobjCDO.SendSet objCDO = nothing%></body></html> If you have CDONTS installed, that code will execute without any errors. Link to comment Share on other sites More sharing options...
pulpfiction Posted March 30, 2006 Author Share Posted March 30, 2006 Hi, Thanks Yahweh for your suggestion. it was so simple and i knew it, but couldnt figure out for such a long time. it works like this...On Error Resume NextobjCDO.Sendif err<>0 then Response.Write "Error: " & Err.Descriptionend ifThank you.PulpFiction Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now