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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T11:47:39+00:00 2026-05-22T11:47:39+00:00

Essentially, I’d like a special form of an Interface for Exceptions that requires anyone

  • 0

Essentially, I’d like a special form of an Interface for Exceptions that requires anyone who uses my object to wrap it with specific catch implementations.

Example

I have an object that sends data to another host. I expect that the realistic implementations will require a way to handle the following exceptions:

  • HostNotFoundException
  • InvalidUsernameException
  • AccountExpiredException
  • DataAlreadyExistsException

Similar to how an Interface or an Abstract class is used to force the creation of methods and properties in derived classes, is there any way I can force a consumer to implement exception handling the way I expect?

On a similar note, I’d also like to force methods (created via Interface or Abstract) to be able to generate certain exceptions. Sure they may be NotImplemented, but I want to tell that developer (who doesn’t read documentation) that they should be considered.

Goal

The benefit of this exception checking is to enable more robust error handling. This would be accomplished by the consumer using the object, and the object creator.

Solution?

The only approach I can think of is T4 templates, but that isn’t as complete of a solution as I would like. I’d love to see this implemented in the language itself.

  • 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-22T11:47:40+00:00Added an answer on May 22, 2026 at 11:47 am

    You can’t force a programmer to do anything except jump through hoops. For example, let’s say you have some method called Frob that does something, and can throw FrobinatorException. You expect programmers to write:

    try
    {
        var result = Frob(foo);
    }
    catch (FrobinatorException)
    {
        // handle exception here
    }
    

    But you find that they don’t. So force them to by defining Frob like this:

    public FrobResult Frob(FrobyThing foo, Action FrobinatorExceptionHandler);
    

    And then programmers have to write something like:

    var result = Frob(
        foo, 
        () => { /* handle FrobinatorException here */; });
    

    Programmers will grumble about having to do that and they’ll end up writing this:

    var StupidExceptionHandler = new Action(() => {});
    var result = Frob(foo, StupidExceptionHandler);
    

    And now you’re worse off than you were because the exceptions are being swallowed, which hides bugs. It’s better if the programmer just ignores the exception handling altogether. At least that way you know when an error occurs.

    There’s simply no way to force good exception handling. At least, not in C# as it currently exists. You can make it more convenient to handle exceptions, but doing so often makes it easier to hide exceptions by swallowing them.

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

Sidebar

Related Questions

Essentially, I have a dynamically generated local HTML form that I would like to
Essentially, I would like to create a database structure that allows for classifying an
Essentially I would like to add a UIImage programmatically to my interface, using: [[self
Essentially, what I'd like is for the value object to maintain a reference to
Essentially I'd like to know just how compatible are the iPhone and the iPod
Essentially what I want to do is impliment a class that can contain a
Essentially, I want to check another object to see if an attribute is set
Essentially here I want the modal form sheet to be transparent so I can
Essentially I would like to apply a bottom-border , but rather than being in
Essentially, what I'm looking for is a function that would allow me to do

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.