Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. not catching my exception

not catching my exception

Scheduled Pinned Locked Moved C#
helpquestion
14 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    blakey404
    wrote on last edited by
    #1

    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

    C L H 3 Replies Last reply
    0
    • B blakey404

      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

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      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 )

      B 2 Replies Last reply
      0
      • B blakey404

        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

        L Offline
        L Offline
        leppie
        wrote on last edited by
        #3

        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)

        B 1 Reply Last reply
        0
        • C Christian Graus

          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 )

          B Offline
          B Offline
          blakey404
          wrote on last edited by
          #4

          Interesting. This is occuring in an event handler, however i thought the method which triggers the event should be on the same thread. I'll look into it as there is some SQL data access going on which may make and asynchronous call. Thanks!

          1 Reply Last reply
          0
          • B blakey404

            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

            H Offline
            H Offline
            Harvey Saayman
            wrote on last edited by
            #5

            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)

            B 1 Reply Last reply
            0
            • L leppie

              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)

              B Offline
              B Offline
              blakey404
              wrote on last edited by
              #6

              it definately isnt being caught :(

              L 1 Reply Last reply
              0
              • H Harvey Saayman

                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)

                B Offline
                B Offline
                blakey404
                wrote on last edited by
                #7

                It is indeed , i intend to use Exception ex once i can actually catch the exception!

                H 1 Reply Last reply
                0
                • B blakey404

                  It is indeed , i intend to use Exception ex once i can actually catch the exception!

                  H Offline
                  H Offline
                  Harvey Saayman
                  wrote on last edited by
                  #8

                  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)

                  B 1 Reply Last reply
                  0
                  • H Harvey Saayman

                    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)

                    B Offline
                    B Offline
                    blakey404
                    wrote on last edited by
                    #9

                    haha thanks :)

                    1 Reply Last reply
                    0
                    • C Christian Graus

                      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 )

                      B Offline
                      B Offline
                      blakey404
                      wrote on last edited by
                      #10

                      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()

                      P 1 Reply Last reply
                      0
                      • B blakey404

                        it definately isnt being caught :(

                        L Offline
                        L Offline
                        leppie
                        wrote on last edited by
                        #11

                        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)

                        B 1 Reply Last reply
                        0
                        • L leppie

                          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)

                          B Offline
                          B Offline
                          blakey404
                          wrote on last edited by
                          #12

                          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()

                          L 1 Reply Last reply
                          0
                          • B blakey404

                            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()

                            L Offline
                            L Offline
                            leppie
                            wrote on last edited by
                            #13

                            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)

                            1 Reply Last reply
                            0
                            • B blakey404

                              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()

                              P Offline
                              P Offline
                              Pete OHanlon
                              wrote on last edited by
                              #14

                              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.

                              My blog | My articles

                              1 Reply Last reply
                              0
                              Reply
                              • Reply as topic
                              Log in to reply
                              • Oldest to Newest
                              • Newest to Oldest
                              • Most Votes


                              • Login

                              • Don't have an account? Register

                              • Login or register to search.
                              • First post
                                Last post
                              0
                              • Categories
                              • Recent
                              • Tags
                              • Popular
                              • World
                              • Users
                              • Groups