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 6198845
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T04:05:05+00:00 2026-05-24T04:05:05+00:00

I am beginner in C# programming. I have encountered small problem during building application

  • 0

I am beginner in C# programming. I have encountered small problem during building application using form. I will try to explain it properly within my abilities and experience. Problem uccured when i tried to handle exception caused by Class1 instantialized in my Form1. Let say i have function “public int Calc(int a, int b)” in Class1. In Form1 i have instantionalized this class to call its “Calc” function. If i want to message an error (f.e: divided by zero) i have to wrap function call into try/catch elements:

//Form1:

Class1 C1 = new Class1();
int a = 5;
int b = 0;
int c = 0;

try{
   c = C1.Calc(a,b)
}
catch(DivideByZeroException e)
{
   // some error handling code
}

… i think this example is not proper OOP technique so i had to decide to put try/catch elements directly into Class1:

//Class1:

public int Calc(int a, int b)
{
    int c = 0;
    try{
      c = a/b;
    }
    catch(DivideByZeroException e)
    {
      // .........
    }
    return c;
}

… question is, how can i get message (DivideByZeroException e) into my Form1 to be able to handle it and message it. I don’t want to create some static function in Form1 just to reach MessageBox class in it from Class1 because it does not make sence in terms of proper OOP functionality and reusability of Class1. I have read about events and delegates (which i understand is simple pointer to function similar to C++) but it is somehow confusing and i failed to apply this technique into my code. Could you please write simple example which would point me to right direction.

thank You guys

Cembo

  • 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-05-24T04:05:08+00:00Added an answer on May 24, 2026 at 4:05 am

    The proper technique really is the first one. If you can’t handle it inside your function, then you have no business trying. Put the exception handling in a place where the exception can be handled and the program can continue (or exit gracefully) and the user be notified of the error in an appropriate fashion.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am having a small problem. I am a beginner to iPhone programming so
I'm a beginner in Java programming language, and I have a problem that I
I am a beginner at shell programming. I have a problem related to nested
I am a beginner in programming. I have a large piece of code. I
I'm beginner in programming. Can somebody please explain (by simple words) what do I
I'm very much still a beginner at programming but I have come across the
hi im a beginner in programming and network development. i have a question regarding
I am a complete, total beginner in programming, although I do have knowledge of
I'm learning C# now and a beginner in the programming world. I have a
Beginner to assembly programming for x86. I have a simple asm file which I

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.