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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T10:59:26+00:00 2026-05-18T10:59:26+00:00

Why c# compiler is not smart enough in the following scenario? void ThrowEx() {

  • 0

Why c# compiler is not smart enough in the following scenario?

    void ThrowEx() {
        throw new Exception();
    }

    int Test() {
        ThrowEx();
    }

…Test()’: not all code paths return a value

Edit: in practice, i want to extract exception throwing logic into a separate method because i’m tired typing stuff like throw new FaultException<MyCustomFault>(new MyCustomFault(), "cannot validate the input");

  • 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-18T10:59:26+00:00Added an answer on May 18, 2026 at 10:59 am

    It doesn’t look between methods; not least, the method could be in a different assembly and could change without rebuilds, or could be virtual, extern, abstract or partial – it would be confusing to spot only a small number of cases.

    You could have the ThrowEx return “int”, and then:

    return ThrowEx();
    

    which would make the compiler happy. Or use generics:

    static T ThrowEx<T>() {...}
    ...
    return ThrowEx<int>();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The following code does not compile: public class GenericsTest { public static void main(String[]
The following Code does not compile Dim BasicGroups As String() = New String() {Node1,
Why does this lambda expression not compile? Action a = () => throw new
I have the following bit of legacy C++ code that does not compile: #include
Alright, I think we all agree that what happens with the following code is
The Visual Studio compiler does not seem to warn on signed/unsigned assignments, only on
I'm not sure, will the visual c ++ compiler express edition work for compiling
I noticed C++ will not compile the following: class No_Good { static double const
The following method does not compile. Visual Studio warns An out parameter may not
Are 'redundant include guards' necessary in Codegear RAD Studio 2009? Is the compiler smart

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.