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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T02:09:51+00:00 2026-06-11T02:09:51+00:00

I have a method in VB.NET which is just a helper for throwing exceptions.

  • 0

I have a method in VB.NET which is just a helper for throwing
exceptions. It will always throw an exception and never returns
However the compiler does not detect this function as a terminating
code path and thus I get warning if I use
variables later on in the code that are not initialized via the exception code path.

Function Foo(y as Integer) As Boolean
    dim x as boolean
    if y > 10
        x = 20
    else
        ThrowHelperFunction("Ouch")
    end if
    return x
End Function

The warning is that x is not initialized on all code paths.

  • 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-11T02:09:52+00:00Added an answer on June 11, 2026 at 2:09 am

    Update:

    There is a way since .NET Standard 2.1 (.NET 5 and newer):

    [DoesNotReturn]
    private void FailFast()
    {
        throw new InvalidOperationException();
    }
    

    Or conditionally:

    private void FailFastIf([DoesNotReturnIf(true)] bool isNull)
    {
        if (isNull)
        {
            throw new InvalidOperationException();
        }
    }
    

    https://learn.microsoft.com/en-us/dotnet/api/system.diagnostics.codeanalysis.doesnotreturnattribute?view=net-8.0

    Original answer:

    I don’t think that you can change that behavior. Instead you can do something like:

    Function Foo(y as Integer) As Boolean
        dim x as boolean
        if y > 10
            x = 20
        else
            throw CreateExceptionHelperFunction("Ouch")
        end if
        return x
    End Function
    

    That is, the helper function can still do some processing. But it will return an exception instead of throwing it.

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

Sidebar

Related Questions

I have c#.net code which calls a method from another external/referenced .net assembly. This
I'm developing an ASP.NET forms webapplication using C#. I have a method which creates
I have some ASP.NET web services which all share a common helper class they
I have a ASP.NET Web Service which exposes a method called DoLogin [WebService(Namespace =
In asp.net mvc3 I want to have a generic method which adds a viewmodel
I have a C# method which accepts a Predicate<Foo> and returns a list of
I have a .NET assembly that has tens of classes and methods which are
I have a method written in VB.NET. It looks like this: Shared Sub SomeMethod(ByVal
If I have a large .NET method, I want to know if it is
In code-behind of an ASP.NET page I have this method: public string TestFunc() {

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.