Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8527823
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T08:39:55+00:00 2026-06-11T08:39:55+00:00

See questions in the comments of the code. I have two classes. Here’s the

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T08:39:57+00:00Added an answer on June 11, 2026 at 8:39 am

    Remove the try catch in DivideNumbers and let the exception bubble up.

    Then Wrap the call to Calculate.DevideNumbers(2, 0); in a try catch block.

    //this class contains controls on the form.
    Class MyApp
    {
        private void btnProcessImages_Click(object sender, EventArgs e)
        {
          try
          {
              Calculate.DevideNumbers(2, 0);
          }
          catch (Exception e)
          {
               DoStuff();
               Return();
          }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a question regarding restricted pointer assignments. See the comments in code for
I have written a following code (see code comments for the question), #include<stdio.h> int
Per this question (see comments near the bottom), I was wondering if anyone knows
I see a lot of questions, both here on SO and elsewhere, about maintaining
This is in reference to the comments in this question : This code in
I've created this simple and pointless assembly (Y86) code to see if I understand
I saw some other similar questions on this topic here but they were not
hi i have two questions about c++ development in eclipse is there a free
I have two questions: 1) How can I get the IP address, and any
I've seen a number of 'code metrics' related questions on SO lately, and have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.