What is output with following Code?

No.of Views1920
Bookmarked0
By RRaveen  On 10 Feb 2011
emailbookmarkadd commentsprint
 

Code

try
            {
                try
                {
                    throw new ApplicationException();
                }
                finally
                {
                    throw new SystemException();

                }

            }
            catch (Exception ex)
            {

                Console.WriteLine(ex.GetType().Name);
            }

Output

SystemException.

Reason

When ApplicationException is raise, it will goes to within the  exception stack, and the  finally block also will run and throw system exception, now system exception also goes to within the exception stack.But when we are print within catch, system exception is most recently added, this is will be retrieved first from stack.so SystemException is result for above code.

 

 
 
About Author
 
RRaveen
Occupation-Software Engineer
Company-TGS
Member Type-Gold
Location-Singapore
Joined date-03 Jun 2009
Home Page-codegain.com
Blog Page-www.codegain.com
- B.Sc. degree in Computer Science. - 4+ years experience in Visual C#.net and VB.net - Obsessed in OOP style design and programming. - Designing and developing Network security tools. - Designing and developing a client/server application for sharing files among users in a way other than FTP protocol. - Designing and implementing GSM gateway applications and bulk messaging. - Windows Mobile and Symbian Programming - Having knowledge with ERP solutions
 
 
Other popular Interview Questions On CSharp
^ Scroll to Top