See questions in the comments of the code.
I have two classes.
Here’s the main class (class 1):
//this class contains controls on the form.
Class MyApp
{
private void btnProcessImages_Click(object sender, EventArgs e)
{
/* if an error occurs in the method below, I want to:
1. Show the error message, and
2. Based on fail or success do different actions.
*/
Calculate.DevideNumbers(2, 0);
}
/*
if the above is successful, I want to do 1 thing,
if not, i want to do something else (with controls on THIS form).
*/
}
And here’s the second class:
Class Calculate
{
public double void DivideNumbers(int num1, int num2)
{
double result = 0.00;
try
{
result = num1/num2;
return result;
}
catch (Exception)
{
throw;
}
}
}
My question is:
What is the best way for DivideNumbers() to report an error back to the calling method?
The caller needs to know if there was an error and what the error message was. How would I go about sending the calling method these two pieces of information?
Remove the try catch in
DivideNumbersand let the exception bubble up.Then Wrap the call to
Calculate.DevideNumbers(2, 0);in a try catch block.