Ok I am automating Outlook from Console Application, which perform number of
actions on the Indox folder like reading new mails, extracting attachment
from new mail, saving attachment to specified path, extracting values from
the saved file, writing values to text file and uploading text file on FTP
server. Now want to terminate the application if any of these processes fails
and log off from outlook and close outlook application. If I don’t use End
statement, it catches the exception show’s it no console and continue with
next process, whose object variables depends on values from the failed
process. In that case the next process might throw another exception.
I want to end the application in case of error, but before that log off and
close outlook. I can easily do it in win form application, by simply using
Me.Dispose in Catch, which does execute Finally before close the application.
But End simple terminates the app without executing Finally.
I hope this make sense
"Shuvro Mazumder [MSFT]" wrote:
I believe that if the try block throws an exception, it'll run the catch
block code and then run the finally code. The finally code will also run if
you do not except, after the try block.
Why are you using an end statement in the catch block?
- Shuvro
--
This posting is provided "AS IS" with no warranties, and confers no rights.
Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm.
"Job Lot" <Jo****@discussions.microsoft.com> wrote in message
news:E9**********************************@microsof t.com... How can I terminate console application in Try.Catch.Finally.End Try block
so that code in Finally gets executed. If I use End statement Finally does
not get executed.
Following is my code written in Console Application.
Module Module1
Sub Main()
Call Testing()
Call Testing2()
End Sub
Private Sub Testing()
Dim i() As Integer = {1, 2, 3}
Try
'This will cause exception
Console.WriteLine(i(3).ToString)
Catch ex As Exception
Console.WriteLine(ex.Message)
'I WANT CONSOLE TO BE TERMINATED HERE SO THAT FINALLY GET EXECUTED. IF I
USE END STATEMENT HERE FINALLY DOES NOT GET EXECUTED.
Finally
i = Nothing
End Try
End Sub
Private Sub Testing2()
Dim i() As Integer = {1, 2, 3}
Try
Console.WriteLine(i(1).ToString)
Catch ex As Exception
Console.WriteLine(ex.Message)
Finally
i = Nothing
End Try
End Sub
End Module