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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T18:52:08+00:00 2026-05-10T18:52:08+00:00

The title may not really explain what I’m really trying to get at, couldn’t

  • 0

The title may not really explain what I’m really trying to get at, couldn’t really think of a way to describe what I mean.

I was wondering if it is good practice to check the arguments that a function accepts for nulls or empty before using them. I have this function which just wraps some hash creation like so.

Public Shared Function GenerateHash(ByVal FilePath As IO.FileInfo) As String         If (FilePath Is Nothing) Then             Throw New ArgumentNullException('FilePath')         End If          Dim _sha As New Security.Cryptography.MD5CryptoServiceProvider         Dim _Hash = Convert.ToBase64String(_sha.ComputeHash(New IO.FileStream(FilePath.FullName, IO.FileMode.Open, IO.FileAccess.Read)))         Return _Hash     End Function 

As you can see I just takes a IO.Fileinfo as an argument, at the start of the function I am checking to make sure that it is not nothing.

I’m wondering is this good practice or should I just let it get to the actual hasher and then throw the exception because it is null.?

Thanks.

  • 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. 2026-05-10T18:52:09+00:00Added an answer on May 10, 2026 at 6:52 pm

    In general, I’d suggest it’s good practice to validate all of the arguments to public functions/methods before using them, and fail early rather than after executing half of the function. In this case, you’re right to throw the exception.

    Depending on what your method is doing, failing early could be important. If your method was altering instance data on your class, you don’t want it to alter half of the data, then encounter the null and throw an exception, as your object’s data might them be in an intermediate and possibly invalid state.

    If you’re using an OO language then I’d suggest it’s essential to validate the arguments to public methods, but less important with private and protected methods. My rationale here is that you don’t know what the inputs to a public method will be – any other code could create an instance of your class and call it’s public methods, and pass in unexpected/invalid data. Private methods, however, are called from inside the class, and the class should already have validated any data passing around internally.

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

Sidebar

Ask A Question

Stats

  • Questions 86k
  • Answers 86k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I would definitely recommend looking at Biscom. They have both… May 11, 2026 at 5:22 pm
  • Editorial Team
    Editorial Team added an answer It depends somewhat on the application, but in general, I'd… May 11, 2026 at 5:22 pm
  • Editorial Team
    Editorial Team added an answer If you get the array key in the foreach loop,… May 11, 2026 at 5:22 pm

Related Questions

The title may not really explain what I'm really trying to get at, couldn't
When I realized I needed to create an index for approximately 50 XHTML pages,
I'm wondering if it's possible to capture details from the web page that a
We're using SQL Server 2005 in a project. The users of the system have
Within an article-oriented page (such as a blog post), the <h1> element (level 1

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.