GeekInterview.com
  I am new, Sign me up!
 
GeekInterview.com  >  Interview Questions  >  Microsoft  >  ASP.NET
Go To First  |  Previous Question  |  Next Question 
 ASP.NET  |  Question 82 of 164    Print  
can one try statement have many catch statements

  
Total Answers and Comments: 7 Last Update: May 01, 2008     Asked by: gajalakshmi 
  
 Sponsored Links

 
 Best Rated Answer
Submitted by: kamal gupta
 

yes one try catch have many catch statement

using System;
class MyClient
{
public static void Main()
{
try
{
  throw new DivideByZeroException("Invalid Division");
}
catch(DivideByZeroException e)
{
  Console.WriteLine("Exception" );
}

Catch(Exception ex)

{

Console.writeline(Ex.message);

}


 Console.WriteLine("LAST STATEMENT");
}
}

we can add following exception

System.OutOfMemoryException
System.NullReferenceException
System.InvalidCastException
System.ArrayTypeMismatchException
System.IndexOutOfRangeException
System.ArithmeticException
System.DevideByZeroException
System.OverFlowException

Above answer was rated as good by the following members:
annmary.mathew
September 26, 2006 08:01:03   #1  
sanjay        

RE: can one try statement have many catch statements

one Try Ststement can have only one catch statement.

when ever error occurs in TRY or can catch in it's approprate catch block only.


 
Is this answer useful? Yes | NoAnswer is useful 0   Answer is not useful 1Overall Rating: -1    
September 26, 2006 14:23:27   #2  
kamal gupta        

RE: can one try statement have many catch statements

yes one try catch have many catch statement

using System;
class MyClient
{
public static void Main()
{
try
{
throw new DivideByZeroException( Invalid Division );
}
catch(DivideByZeroException e)
{
Console.WriteLine( Exception );
}

Catch(Exception ex)

{

Console.writeline(Ex.message);

}


Console.WriteLine( LAST STATEMENT );
}
}

we can add following exception

System.OutOfMemoryException

System.NullReferenceException

System.InvalidCastException

System.ArrayTypeMismatchException

System.IndexOutOfRangeException

System.ArithmeticException

System.DevideByZeroException

System.OverFlowException

 
Is this answer useful? Yes | NoAnswer is useful 1   Answer is not useful 0Overall Rating: +1    
October 06, 2006 02:59:51   #3  
Nagender Rachakonda        

RE: can one try statement have many catch statements

Yes


 
Is this answer useful? Yes | No
October 16, 2006 12:56:56   #4  
anji        

answer wrong
one try statement may contain many catch blocks
 
Is this answer useful? Yes | No
February 23, 2007 05:42:01   #5  
NagaSekhar Karanam        

RE: can one try statement have many catch statements

one try block have many catch blocks which r mutually exclusive


 
Is this answer useful? Yes | No
May 01, 2008 10:03:58   #6  
khopda Member Since: May 2008   Contribution: 6    

RE: can one try statement have many catch statements
Yes dear. Many try catch blocks can be associated with one try block but only one catch block's code gets executed whenever there is an error in the try block. I hope it answers your question!
 
Is this answer useful? Yes | No
May 01, 2008 10:05:26   #7  
khopda Member Since: May 2008   Contribution: 6    

RE: can one try statement have many catch statements
Don't trust the people who say that a try block can have only one catch block...
 
Is this answer useful? Yes | No


 
Go To Top


 Sponsored Links

 
About Us -  Privacy Policy -  Terms and Conditions -  Contact -  Ask Question -  Propose Category -  Site Updates 

Copyright © 2005 - 2009 GeekInterview.com. All Rights Reserved

Page copy protected against web site content infringement by Copyscape