Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Try/Catch/Finally question. Somewhat short on time.

Posted on 2007-03-28
3
Medium Priority
?
290 Views
Last Modified: 2010-04-16
just a quick question about   Try/Catch/Finally   blocks.

Lets say I have a bool function I'm writing.

try
{
   //some code
}
catch (Exception)
{
   return false;
}
finally
{
  //some code
}
return true;


if an exception occurs in the try block, will the finally block still execute? or does the return statement immediately leave the function?
0
Comment
Question by:raw_enha
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 2

Accepted Solution

by:
empoalp earned 2000 total points
ID: 18808673
Finally code is executed.

You can check it withs this code:

    class Program
    {
        static void Main(string[] args)
        {
            func();
            Console.Read();
        }

        public static bool func()
        {
            try
            {
                Console.WriteLine("try");
                Int32.Parse("jjjj");
            }
            catch (Exception)
            {
                Console.WriteLine("catch");
                return false;
            }
            finally
            {
                Console.WriteLine("finally");
            }
            return true;
        }
    }
0
 
LVL 15

Expert Comment

by:angus_young_acdc
ID: 18808718
Yes your finally is executed, however you wouldnt loop back to re-do what failed in the try block.  

It is really just for catching and dealing with your exceptions
0
 
LVL 16

Expert Comment

by:AlexNek
ID: 18809191
But, please never do it in a real application.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

670 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