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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T05:09:55+00:00 2026-06-14T05:09:55+00:00

For example if you pass a car into a sub that makes use of

  • 0

For example if you pass a car into a sub that makes use of a car who should be checking for null references?

Should I even bother wrapping this code in the below if statement? It seems quite redundant, obviously I could have given a better example because I can’t catch the exception and handle it in any way.

Or should I just let the exception bubble up to the caller?

For example:

Public Sub CarService(ByVal car As ICar)
    If car IsNot Nothing Then
        'do logic here 
    Else : Throw New ArgumentNullException
    End If
End Sub
  • 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-14T05:09:57+00:00Added an answer on June 14, 2026 at 5:09 am

    Throwing a NullReferenceException yourself is actually pointless. As this is

    1. the same exception that the CLR would raise (at least when you
      access the same reference that you manually check for null) and
    2. is discouraged anyway. See Remarks
      here. For a related discussion see Is it necessary to throw a NullReferenceException from an extension method?.

    You should however, arguably at least for the public API surface, check for null references and throw an ArgumentNullException.

    Public Sub CarService(ByVal car As ICar)
        If car Is Nothing Then
            Throw New ArgumentNullException("car")
        End If
        ' do logic here
    End Sub
    

    Or look into Code Contracts.

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

Sidebar

Related Questions

I want pass a sub data type into function. An example: data Car a
How to pass an array into a SQL Server stored procedure? For example, I
How do I pass input into the command line using code. For example, I
How to pass a $_GET variable into function? $_GET['TEST']='some word'; public function example() {
example: if I pass Id = 564 then I should be able to read
How do I pass 2 lists into Parallel.ForEach ? Example: List<Person> a = new
For example: class Car: pass jeep = Car() jeep.color = 'blue' This is perfectly
When making something const in C++ what makes it that you cannot for example
Can you pass by reference with R ? for example, in the following code:
I want to pass a url like http://example.com/test?a=1&b=2 in url segment of codeigniter. I'm

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.