Announcement

Collapse
No announcement yet.

Try Catch Problem

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Try Catch Problem

    Hallo,

    ich benutze in einer Methode einen Try-Catch-Block. Wenn ich den Ablauf mit dem Debugger anschaue passiert etwas total seltsames. Der Try Block wird ohne Fehler jedes Mal bis zum Ende ausgeführt. Aber anschließend wird die letzte Zeile des Catch-Blocks ausgeführt, egal was in dieser Zeile steht.
    Es handelt sich um folgende Methode:

    Code:
        
        Sub SendMail(ByVal SMTPServer As String, ByVal mailtarget As String, ByVal mailsubject As String, ByVal mailbody As String, ByVal mailorigin As String, ByVal contype As String)
            Dim objEmail
            Dim strerr = ""
    
            Try
                objEmail = CreateObject("CDO.Message")
                objEmail.Subject = mailsubject
                objEmail.To = mailtarget
                objEmail.From = mailorigin
    
                If contype = "html" Then
                    objEmail.HTMLBody = mailbody
                Else
                    objEmail.TextBody = mailbody
                End If
                If Not (attnames Is Nothing) Then
                    For i As Integer = 0 To UBound(attnames) - LBound(attnames)
                        objEmail.AddAttachment(ATTACHMENTDIR & attnames(i))
                    Next
                End If
    
                objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
                objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = SMTPServer
                objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = SMTPPORT
                objEmail.Configuration.Fields.Update()
                objEmail.Send()
            
            Catch ex As Exception
    
                WriteDebugLog("ERROR", "Fehlermeldung:" & "E-Mail konnte nicht versendet werden." & "(" & CStr(ex.Source) & ")")
                WriteDebugLog("ERROR", "Fehlermeldung:" & strerr & "(" & CStr(ex.Source) & ")")
                WriteDebugLog("ERROR", "TEST1")
                WriteDebugLog("ERROR", "TEST2")
                Exit Try
    
            End Try
    
        End Sub
    Ich habe an das Ende des Catch- Blocks als kleinen Workaround das Exit Try geschrieben. Denn wenn er das ausführt passiert ja nicht wirklich was.
    Allerdings würde mich dennoch interessieren, an was das liegt.
    Ist das irgendein komischer Bug vom Debugger, vom Kompiler oder von sonstwas?

    Vielen Dank schonmal.
    Zuletzt editiert von Boinji; 09.03.2009, 14:24.

  • #2
    Originally posted by Boinji View Post
    Exit Try
    [/CODE]
    Allerdings würde mich dennoch interessieren, an was das liegt.
    Ist das irgendein komischer Bug vom Debugger, vom Kompiler oder von sonstwas?

    Vielen Dank schonmal.
    Eventuell weil es schon am Ende ist, sieht es nur so aus als würde nichts passieren.

    Comment

    Working...
    X