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

  • Home
  • SEARCH
  • 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 902823
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T15:46:45+00:00 2026-05-15T15:46:45+00:00

I am working on application where user invokes a method from UI , on

  • 0

I am working on application where user invokes a method from UI , on this I am calling a method from business class which calls another methods

UI–> Method1 –>Method2 –> Method3

I want to display the error message to user if any exception occurs in any of the method.

Shall I go with throwing the exception directly to the caller method and at the UI layer I will catch exception and display the message.

Apart from Throwing exceptions and catching it at caller is there any better way to handle it?

I do not want to use the C++ convention where integer is returned as the result.

  • 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-15T15:46:46+00:00Added an answer on May 15, 2026 at 3:46 pm

    Given your example of UI–> Method1 –>Method2 –> Method3, I would make sure that the UI has a try/catch, but then none of the other methods should catch exceptions unless they can handle them without re-throwing. And even if they handle the exception, you should question whether that exception should happen in the first place. If you handle an exception and go about your merry way, then that exception is part of your normal process flow which is a serious code smell.

    Here are my recommendations:

    1) Put your exception handling code in all your UI events, and then have the actual action farmed off to some other method. Don’t scatter exception handling code all over the place. It’s clunky and makes the code hard to read.

    protected void Button1_Click(object sender, EventArgs e) {
       try {
          DoSomething();
       }
       catch Exception e {
          HandleError(e);
       }
    }
    

    2) Don’t do this. You’ll lose your stack trace and the next developer who maintains your code will hunt you down.

    try {
       DoSomething();
    }
    catch Exception e {
       throw e; // don't rethrow!!!
    }
    

    If you aren’t going to handle the exception, don’t catch it. Or, use a naked throw like this:

    try {
       DoSomething();
    }
    catch SomeException e {
       HandleException(e);
    }
    catch {
       throw ; // keep my stack trace.
    }
    

    3) Only throw exceptions in exceptional circumstances. Don’t have try/catch blocks as part of your normal process flow.

    4) If you’re going to throw an exception, don’t ever throw a System.Exception. Derive an exception object and throw it. I often just a generic BusinessException class. This way, users of your code can determine what exceptions you made up and which ones are system/environment related.

    5) Throw ArgumentException, ArgumentNullException, or ArgumentOutOfRangeException if a method caller violates the contract (preconditions) of your method. If you catch one of these, it’s a programming bug. A user should never see these exceptions.

    If you remember that exceptions should be a very rare occurrence and that handling them is almost always a UI concern (so the bulk of your try/catch code should stay at the UI level) you will do well.

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

Sidebar

Ask A Question

Stats

  • Questions 449k
  • Answers 449k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer In Solution Explorer in Visual Studio (or VWD, if you… May 15, 2026 at 8:08 pm
  • Editorial Team
    Editorial Team added an answer You need to determine if the field exists before you… May 15, 2026 at 8:08 pm
  • Editorial Team
    Editorial Team added an answer The tool you really want to use is GPSBabel. If… May 15, 2026 at 8:08 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.