Can we have try block without catch?

 Posted by Jpchoudhari on 9/13/2011 | Category: .NET Framework Interview questions | Views: 10130 | Points: 40
Answer:

Yes.

We can write Try { } Finally { } block. In this case exception will be thrown in try block if it is but code inside finally block will execute.

Here any exception in CallFirstMethod() or CallSecondMethod() will be handled by MainMethod() and finally block will execute always to perform any cleanups for respective methods.
public void MainMethod()

{
try
{
CallFirstMethod();
CallSecondMethod();
}
Catch(Exception ex)
{
//handle exception
}
}
publiv void CallFirstMethod()
{
try
{
//code
}
finally
{
//cleanups
}
}
publiv void CallSecondMethod()
{
try
{
//code
}
finally
{
//cleanups
}
}


Asked In: Many Interviews | Alert Moderator 

Comments or Responses

Posted by: Mcadeepuraj on: 9/14/2011 | Points: 10
nice
Posted by: Biswarup90 on: 11/22/2011 | Points: 10
I want some Interview question ....plz send me rply plz.
Posted by: Biswarup90 on: 11/23/2011 | Points: 10
What is AppDomain?

An application domain is the CLR equivalent of an operation system’s process. An application domain is used to isolate applications from one another. This is the same way an operating system process works. The separation is required so that applications do not affect one another. This separation is achieved by making sure than any given unique
virtual address space runs exactly one application and scopes the resources for the process or application domain using that addess space.

Login to post response

More Interview Questions by Jpchoudhari