Solved

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

Posted on 2007-11-19
2
1,759 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

867 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

20 Experts available now in Live!

Get 1:1 Help Now