How to handle exception

Posted by Laghaterohan under C# on 10/11/2011 | Points: 10 | Views : 975 | Status : [Member] | Replies : 2
Hi,
Examine the following scenario

public class A()
{
try
{
B();
}
catch()
{
//code
}
finally
{

}
}
public class B()
//code depending on the B() output
{
try
{
// code
}
catch
{
//code
}
}

In the above case if any exception occurs in class B(), how will i notify class A that exception has occured and should not continue with the following code since the that code depends on the B's output.
Please do let me know.

Regards,
Rohan Laghate

Best Regards,
Rohan Laghate



Responses

Posted by: Ndebata on: 10/11/2011 [Member] Starter | Points: 25

Up
0
Down
Throw it from Class B and catch it in ClassA
public class B()

//code depending on the B() output
{
try
{
// code
}
catch(Exception ex)
{
throw ex;
}
}



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

Posted by: perfectchourasia-9163 on: 11/17/2011 [Member] Starter | Points: 25

Up
0
Down
use of try catch final is the best way. study on it

ER sandeep chourasia
sandeepchrs@yahoo.com (on facebook)
http://www.aspnetcodes.com/

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

Login to post response