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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T00:05:09+00:00 2026-06-10T00:05:09+00:00

I was using the following pattern for catch blocks in my data class: }

  • 0

I was using the following pattern for catch blocks in my data class:

} catch (OracleException e) {
    log.Error(e, e);
    ExceptionNotification.Show(e, "Platypus data not found for Platypus");
    throw;
}

(the “log” is log4net; after that is our fancy exception display dialog).

When I remove the “throw,” I get “not all code paths return a value”

If I reach the exception block, the object I want to return (an OracleDataTable, a List, a Dictionary<>, or a custom class, usually, might be null, or at best not feeling too well. What can I return to mollify the compiler?

  • 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-10T00:05:10+00:00Added an answer on June 10, 2026 at 12:05 am

    Never mollify compilers. Boss them around and make them do what you need, or they’ll get above themselves.

    Compilers have a submissive nature, and like being bossed; the moment you start mollifying them they stop helping you. Some of them even bring their own paddles.

    If you have to ask this question, you’re probably taking the wrong approach. The answer to “what value to return on swallowing an exception” is “the value that is blatantly obvious as the value to return in swallowing this exception in this place”. If nothing is that obvious, then it shouldn’t be swallowed (the same applies to “the obvious place in the loop to continue from after swallowing this exception in this place”). And then double-check your assumptions because the “obvious” thing can still be wrong.

    You should also comment any swallowing clearly, because it’s so often a bad thing that anyone reading the code is going to start with the assumption that it’s bad code unless you explain why it isn’t.

    You’re better off with one of the following:

    throw;
    

    Let the exception pass up. Something handles it, or something doesn’t and you get an error message and a shut-down (not always the worse thing, depending on the application and how likely the error seemed to be).

    throw e;
    

    Which would throw the exact same exception (literally the same instance) but will be seen as coming from your code rather than the code you called into. This is so rarely the right thing that some people will tell you it’s plain wrong. I disagree, but I do agree the cases are rare – like swallowing, if it isn’t the obvious choice it’s almost certainly the wrong choice and if it is the obvious choice it might still be the wrong choice.

    throw new ExceptionTypeAppropriateToThisMethodCall("a useful message");
    

    OR

    throw new ExceptionTypeAppropriateToThisMethodCall("a useful message", e);
    

    Here you turn the exception into something more closely related to the service your method supplies to the calling code. The second form wraps the inner exception for diagnostic goodness.

    In some cases, just killing the application or unloading the app-domain can be the best choice, though that’s mostly going to happen from not having anything handle the exception at any point.

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

Sidebar

Related Questions

I've seen others using the following pattern. var bar = function foo(){}; console.log(bar); //
I am using the following pattern to update my SQL Server records using Linq
How to capture the following pattern using JavaScript regular expressions? I would like to
We are frequently using the following code pattern in our JavaScript code if (typeof(some_variable)
I am trying to find all the digits following a certain String pattern using
I am using following code to show a spinning wheel: $(#loading) .hide() .ajaxStart(function(){ $(this).show();
I have the following design pattern: var myObjectWithEvents = new ObjectWithEvents(); using (var mre
I'm having trouble recognising a potential hash character. I am using the following pattern
I'm using the following pattern in C#: IList<foo> x = y.Select(a => new foo
I am using the following DecimalFormat pattern: // Use ThreadLocal to ensure thread safety.

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.