Solved

how does break affect try .. catch... finally in C# 2003

Posted on 2007-11-19
2
1,758 Views
Last Modified: 2008-02-01
In this scenario, will the break cause the finally to be skipped?


foreach (Xceed.Grid.DataRow dr in this.gcResults.DataRows)

			{

				foreach (Xceed.Grid.DetailGrid dGrid in dr.DetailGrids)

				{

					foreach (Xceed.Grid.DataRow drSub in dGrid.DataRows)

					{

						if (Convert.ToBoolean(drSub.Cells[6].Value) == true)

						{

							try

							{

								c.Open();

								//expire the old record

								//insert the new record

							}

							catch (Exception ex)

							{

								MessageBox.Show (this,"Failure To Write Record | " + ex.Message,"Commercial Bag PA Bulk Update",MessageBoxButtons.OK,MessageBoxIcon.Warning);

								break;

							}

							finally

							{

								if (c.State != ConnectionState.Closed)

								{

									c.Close();

								}

							}

						}

					}

				}

			}

Open in new window

0
Comment
Question by:g_johnson
2 Comments
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 350 total points
ID: 20315491
break where?

anyhow, break will only terminate the closest loop or switch, so it will only terminate that. it will NOT skip the finally.
0
 
LVL 15

Assisted Solution

by:Solar_Flare
Solar_Flare earned 150 total points
ID: 20315524
Finally will ALWAYS be executed, even returning a function from inside the try..catch will still execute the finally code
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

747 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

14 Experts available now in Live!

Get 1:1 Help Now