not catching my exception
-
try
{
smtpClient.Send(mailMessage);
}
catch (Exception ex)
{
eventLogImport.WriteEntry("SMTP Email error: could not send email.", EventLogEntryType.Warning);
}Hi, The above code still throws an unhandled SMTPException when smtpClient.Send is called. SMTPException is derived from System.Exception so should it not be caught? Thanks
-
try
{
smtpClient.Send(mailMessage);
}
catch (Exception ex)
{
eventLogImport.WriteEntry("SMTP Email error: could not send email.", EventLogEntryType.Warning);
}Hi, The above code still throws an unhandled SMTPException when smtpClient.Send is called. SMTPException is derived from System.Exception so should it not be caught? Thanks
Hmmm... if the smtpClient uses another thread, this won't be caught, you need to actually set a handler for exceptions from another thread.
Christian Graus Please read this if you don't understand the answer I've given you "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
-
try
{
smtpClient.Send(mailMessage);
}
catch (Exception ex)
{
eventLogImport.WriteEntry("SMTP Email error: could not send email.", EventLogEntryType.Warning);
}Hi, The above code still throws an unhandled SMTPException when smtpClient.Send is called. SMTPException is derived from System.Exception so should it not be caught? Thanks
-
Hmmm... if the smtpClient uses another thread, this won't be caught, you need to actually set a handler for exceptions from another thread.
Christian Graus Please read this if you don't understand the answer I've given you "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
-
try
{
smtpClient.Send(mailMessage);
}
catch (Exception ex)
{
eventLogImport.WriteEntry("SMTP Email error: could not send email.", EventLogEntryType.Warning);
}Hi, The above code still throws an unhandled SMTPException when smtpClient.Send is called. SMTPException is derived from System.Exception so should it not be caught? Thanks
i see something else thats wrong-ish your compiler should be giving you a warning "ex is declared but never used"... if you don't intend on using ex don't declare it...
catch (Exception)
{
eventLogImport.WriteEntry("SMTP Email error: could not send email.", EventLogEntryType.Warning);
}Harvey Saayman - South Africa Junior Developer .Net, C#, SQL
you.suck = (you.passion != Programming)
-
blakey404 wrote:
SMTPException is derived from System.Exception so should it not be caught?
Of course it will be caught...
xacc.ide - now with TabsToSpaces support
IronScheme - 1.0 alpha 4a out now (29 May 2008) -
i see something else thats wrong-ish your compiler should be giving you a warning "ex is declared but never used"... if you don't intend on using ex don't declare it...
catch (Exception)
{
eventLogImport.WriteEntry("SMTP Email error: could not send email.", EventLogEntryType.Warning);
}Harvey Saayman - South Africa Junior Developer .Net, C#, SQL
you.suck = (you.passion != Programming)
-
if thats the case than its all good :) ive seen programmers IGNORE compiler warnings and that just irritates the living S**T out of me... just thought id point it out incase you didnt notice :) good luck
Harvey Saayman - South Africa Junior Developer .Net, C#, SQL
you.suck = (you.passion != Programming)
-
if thats the case than its all good :) ive seen programmers IGNORE compiler warnings and that just irritates the living S**T out of me... just thought id point it out incase you didnt notice :) good luck
Harvey Saayman - South Africa Junior Developer .Net, C#, SQL
you.suck = (you.passion != Programming)
-
Hmmm... if the smtpClient uses another thread, this won't be caught, you need to actually set a handler for exceptions from another thread.
Christian Graus Please read this if you don't understand the answer I've given you "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
Out of interest, here is my call stack, I dont think there should be an issue but if you do could you let me know, thanks again! at System.Net.Mail.MailCommand.CheckResponse(SmtpStatusCode statusCode, String response) at System.Net.Mail.MailCommand.Send(SmtpConnection conn, Byte[] command, String from) at System.Net.Mail.SmtpTransport.SendMail(MailAddress sender, MailAddressCollection recipients, String deliveryNotify, SmtpFailedRecipientException& exception) at System.Net.Mail.SmtpClient.Send(MailMessage message) at TransactionService.ServiceMain.importLogic_DataAccessSQLException(Object sender, ChainStoreTransactionImportExceptionEventArgs e) at BusinessLogic.ChainBranchTransactionLogic.OnDataAccessSQLException(Object sender, ChainStoreTransactionImportExceptionEventArgs e) at BusinessLogic.ChainBranchTransactionLogic.ChainStoreTransactionImport(EPOSTransactionDataSet transactionDataSet) at TransactionService.ServiceMain.ProcessTransactionFiles() at System.Threading.ThreadHelper.ThreadStart_Context(Object state) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) at System.Threading.ThreadHelper.ThreadStart()
-
blakey404 wrote:
it definately isnt being caught :(
So what exception are you getting where? Please post a stacktrace with line numbers and post the 3-4 lines aournd where it claims the exception is happening.
xacc.ide - now with TabsToSpaces support
IronScheme - 1.0 alpha 4a out now (29 May 2008) -
blakey404 wrote:
it definately isnt being caught :(
So what exception are you getting where? Please post a stacktrace with line numbers and post the 3-4 lines aournd where it claims the exception is happening.
xacc.ide - now with TabsToSpaces support
IronScheme - 1.0 alpha 4a out now (29 May 2008)not the most fun in the world debugging, as i'm developing a windows service; at System.Net.Mail.MailCommand.CheckResponse(SmtpStatusCode statusCode, String response) at System.Net.Mail.MailCommand.Send(SmtpConnection conn, Byte[] command, String from) at System.Net.Mail.SmtpTransport.SendMail(MailAddress sender, MailAddressCollection recipients, String deliveryNotify, SmtpFailedRecipientException& exception) at System.Net.Mail.SmtpClient.Send(MailMessage message) at TransactionService.ServiceMain.importLogic_DataAccessSQLException(Object sender, ChainStoreTransactionImportExceptionEventArgs e) at BusinessLogic.ChainBranchTransactionLogic.OnDataAccessSQLException(Object sender, ChainStoreTransactionImportExceptionEventArgs e) at BusinessLogic.ChainBranchTransactionLogic.ChainStoreTransactionImport(EPOSTransactionDataSet transactionDataSet) at TransactionService.ServiceMain.ProcessTransactionFiles() at System.Threading.ThreadHelper.ThreadStart_Context(Object state) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) at System.Threading.ThreadHelper.ThreadStart()
-
not the most fun in the world debugging, as i'm developing a windows service; at System.Net.Mail.MailCommand.CheckResponse(SmtpStatusCode statusCode, String response) at System.Net.Mail.MailCommand.Send(SmtpConnection conn, Byte[] command, String from) at System.Net.Mail.SmtpTransport.SendMail(MailAddress sender, MailAddressCollection recipients, String deliveryNotify, SmtpFailedRecipientException& exception) at System.Net.Mail.SmtpClient.Send(MailMessage message) at TransactionService.ServiceMain.importLogic_DataAccessSQLException(Object sender, ChainStoreTransactionImportExceptionEventArgs e) at BusinessLogic.ChainBranchTransactionLogic.OnDataAccessSQLException(Object sender, ChainStoreTransactionImportExceptionEventArgs e) at BusinessLogic.ChainBranchTransactionLogic.ChainStoreTransactionImport(EPOSTransactionDataSet transactionDataSet) at TransactionService.ServiceMain.ProcessTransactionFiles() at System.Threading.ThreadHelper.ThreadStart_Context(Object state) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) at System.Threading.ThreadHelper.ThreadStart()
blakey404 wrote:
at System.Net.Mail.SmtpClient.Send(MailMessage message)
It must catch it (you still dont say the exact exception type I was asking for), if it does not, either your code is wrong, or something else. So how do you get that stacktrace? How did you print it out/copy it? I also note, you turned off debugging (and hence no linenumbers). It is not possible to accurately pinpoint the exact exception point in an optimized run mode. Lastly debugging a service is no more dificult to debug than any other application. 1. Start service. 2. Set a few breakpoints. 3. Attach to service process with debugger. 4. Wait for exception.
xacc.ide - now with TabsToSpaces support
IronScheme - 1.0 alpha 4a out now (29 May 2008) -
Out of interest, here is my call stack, I dont think there should be an issue but if you do could you let me know, thanks again! at System.Net.Mail.MailCommand.CheckResponse(SmtpStatusCode statusCode, String response) at System.Net.Mail.MailCommand.Send(SmtpConnection conn, Byte[] command, String from) at System.Net.Mail.SmtpTransport.SendMail(MailAddress sender, MailAddressCollection recipients, String deliveryNotify, SmtpFailedRecipientException& exception) at System.Net.Mail.SmtpClient.Send(MailMessage message) at TransactionService.ServiceMain.importLogic_DataAccessSQLException(Object sender, ChainStoreTransactionImportExceptionEventArgs e) at BusinessLogic.ChainBranchTransactionLogic.OnDataAccessSQLException(Object sender, ChainStoreTransactionImportExceptionEventArgs e) at BusinessLogic.ChainBranchTransactionLogic.ChainStoreTransactionImport(EPOSTransactionDataSet transactionDataSet) at TransactionService.ServiceMain.ProcessTransactionFiles() at System.Threading.ThreadHelper.ThreadStart_Context(Object state) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) at System.Threading.ThreadHelper.ThreadStart()
Interestingly enough, I see that the first thing this does is start off a new thread. As Christian said, this could well be the issue. Try using Application.ThreadException to catch the exception.
Deja View - the feeling that you've seen this post before.