If any exception comes how it will trace?

Posted by Naga116 under C# on 7/31/2011 | Points: 10 | Views : 971 | Status : [Member] | Replies : 2
I am using the keyword of "Using" in c#. If any exception come how it will handle.

If
{
}
exception ex
throws{
catch
}
Finally
NOthing..

This code will be internally executed.This code is not required write explicitly. How the developer will know the exception

Nagaraju


Responses

Posted by: SheoNarayan on: 7/31/2011 [Administrator] HonoraryPlatinum | Points: 25

Up
0
Down
If you are writing code with the "using" block in the class library (BAL or DAL etc.), you do not need to wrap them into try catch.

The exception handling code can be written in your code behind files. So when you are calling the BAL methods, call them inside the try block and handle it.

In case you have a scenario, when you need to catch the exception from the error occurred in the using block, keep it inside the try block.

eg.
try

{
using(yourOb o = new yourOb)
{ }
}
catch (Exception ee)
{

}


Thanks

Regards,
Sheo Narayan
http://www.dotnetfunda.com

Naga116, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Akiii on: 8/1/2011 [Member] Bronze | Points: 25

Up
0
Down
Hi Sheo sir,

I just have a question....
Suppose i have a Class which contains all my connection details. When i use the connection object, should i write in try-catch block ?

Thanks and Regards
Akiii

Naga116, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response