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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T22:41:54+00:00 2026-06-15T22:41:54+00:00

I am actually writing a library class which could be used by multiple classes.

  • 0

I am actually writing a library class which could be used by multiple classes. I am simplying the example so as to make a point. Lets say I have three classes: A, B and C:

public class B
{
  public static string B_Method()
  {
    string bstr = String.Empty;

    try
       {


        //Do Something

       }

    catch
        {

        //Do Something

        }

  return bstr;

}

B is the library class that I am writing. Now there are lets say two other classes say A and C:

public class A
{
  public void A_Method()
  {
   string astr = B.B_Method();
  }

}

public class C
{
 public void C_Method()
  {
   string cstr = B.B_Method();
  }

}

The question is regarding the exception handling. I want the respective method of the two classes A and B to handle the exception occuring in B_Method in their own different ways.

I looked for framework design pattern, but felt that was not useful.

  • 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-15T22:41:55+00:00Added an answer on June 15, 2026 at 10:41 pm

    The approach that I usually follow is this:

    • If my method can do something useful with the exception, I catch it and do that.
    • If not, I don’t catch it and leave it up to calling code to deal with it.

    The only places where I would put a “catch all” block, is at entry points in UI code (such as event handlers for button clicks and such), since not catching exceptions there might take the process down.

    This also means that exception clauses should catch the specific exceptions that you can handle.

    One approach that I sometimes see is to catch the exception, wrap it in a new exception type and throw that. While that offers you some traceability, I also feel that it removes some options in the exception handling in calling code, such as having specific catch clauses for different scenarios. In these cases you will instead need to have if-clauses inspecting the inner exception with is less readable in my eyes.

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

Sidebar

Related Questions

I am writing library which wraps a lot of functions and methods from other
I'm writing a library that provides a Service that is used by other developers
I am writing a class library to interact with a domain Active Directory. In
I am writing a class library to perform operations on a site outside my
I am writing a JAR library that will be used on desktop and also
I have a library that I'm writing which processes keystroke events using the Win32
Is there any way to access private variables of other class.Actually I am writing
I'm trying to learn Lisp (elisp, actually), and I tried writing the following function
I am writing a Java program to read and XML file, actually an iTunes
I'm writing some C# bindings for the C library controlling the pulseaudio sound server,

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.