Saturday, 2 May 2015

Exceptions Handling in dot Net

1) What is the result of following program?
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            try
            {
                Console.WriteLine("ABC");
            }
            catch (Exception ex)
            {             
                
            }
            finally
            {
                 return;
 Console.WriteLine("one");
                
            }
        }
    }
}
Ans) Compile time error
Error Control cannot leave the body of a finally clause

2) Can multiple catch blocks be executed ?
Ans) No, Multiple catch blocks can’t be executed. Once the proper catch code executed, the control is transferred to the finally block and then the code that follows the finally block gets executed.

3)  

No comments:

Post a Comment