Solved

Get confuse with Try..Catch..Finally block

Posted on 2004-10-18
2
187 Views
Last Modified: 2010-04-24

Hi experts, I have an question about Exception Handling please help.

I know that we use Try structure in vb.net to catch any error.
Try
....
...
Catch e as excetion
...
...
Finally
...
...

The question is that: The Finally block will always execute, right? but when I use try in try (nested try) only the last finally block will execute. So how can I make rest of finally block execute all?

Thank you.
0
Comment
Question by:veayou
2 Comments
 
LVL 10

Accepted Solution

by:
123654789987 earned 300 total points
Comment Utility
This is a tested solution try this

nested try/finally statement

    static void Main()
        while (true)
            try
                try
                    Console.WriteLine("Before break");
                    break;
                end try
                finally
                    Console.WriteLine("Innermost finally block");
                end finally
          end try
            finally
                Console.WriteLine("Outermost finally block");
           end finally
       
        Console.WriteLine("After break");
   

Output is as follows

    Before break
    Innermost finally block
    Outermost finally block
    After break
0
 
LVL 7

Assisted Solution

by:J_Mak
J_Mak earned 200 total points
Comment Utility
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now