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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T04:18:17+00:00 2026-05-23T04:18:17+00:00

Something occurs that is more or less expected with normal use of a .NET

  • 0

Something occurs that is more or less expected with normal use of a .NET library you are writing. You need to notify the user/UI/caller that this event has occurred, even though it is expected and not exceptional. Do you:

A) Throw an exception, let the UI catch it and deal with it.

B) Raise some type of event that the UI can listen for.

C) Do something else

Which of the above do you do? If both, what are your guidelines for when to throw an exception vs. raise an event? What are the pros and cons of each?

Edit:

Here is an example I’m facing. My library uses a third party application to print shipping labels by starting the third party application and passing an XML file as an argument, which is processed as a batch type operation. If the third party application is already open by a user, it must be shut down before my library can call it for the batch operation. My library checks to see if the application is running, and if it is, it simply stops and needs to notify the user that they should close the third party application and try again. I fully expect this to happen as part of the normal use of the library. Throw an exception, or raise an event?

  • 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-23T04:18:17+00:00Added an answer on May 23, 2026 at 4:18 am

    Exceptions are different from events because you have to handle them.

    If you think the client code just can’t go on, throw an exception (examples: network error, security error, bad input). Otherwise, kindly acknowledge that something has happened by raising an event but don’t force the caller to react immediately.

    Also note that events may be raised and handled asynchronously and are not bound to particular caller’s actions, whereas exceptions always get thrown in context of a specific method call. Of course, you can throw exceptions from anywhere but if the client code doesn’t expect them where they occur, they become essentially useless because unhandled.

    See also this thread.


    As for your situation:

    Apparently, in your case workflow cannot continue unless the third-party application is closed, and this situation is not exactly normal, meaning it’s more of a technical restriction than a true workflow option. You also can’t let the client code just ignore it. This fits exceptions immediate-response nature.

    However, it is also true that this situation is not all-exceptional because on some level it is known and expected.

    Because of that, I suggest you do this:

    • introduce a CanRunNow property that determines if application is running;
    • check this property in client code prior to calling Run method (let’s assume it’s called so);
    • in Run method, do the check again, and if this time CanRunNow is false, throw an exception (now this is unexpected!)

    This way you give the client code freedom and responsibility to either do a check and stay safe, or to go right ahead (and possibly get an exception). Whatever behavior you choose, make sure to document it!

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

Sidebar

Related Questions

Something that has always bugged me is how unpredictable the setTimeout() method in Javascript
Something that would really reload the page or resource, ignoring whatever might be in
quick back story-- I am working on ASP.Net based template editor that lets authors
I wonder if this is something very simple that I'm just missing, or if
I have a BizTalk schema that looks something like this: <Root> <Header> <SomeData></SomeData> <Detail>
What is the size that a reference in Android's Java VM consumes? More info:
Having an issue where compiling some code that makes use of HttpContextBase is throwing
Something i've never really done before, but what is the best way to make
Something I have always been interested in out of curiosity, is there a tool
Something like var life= { users : { guys : function(){ this.SOMETHING.mameAndDestroy(this.girls); }, girls

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.