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 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

Related Questions

the title may not be appropriate because I don't really know how I should
May be my title is not clear. I am looking for some kind of
Title says what i'm trying to do. I can successfully generate an assembly if
Title might be a bit confusing, so let me explain. I have a website
Title: Eclipse plug-in development Unable to instantiate class due to java.lang.NoClassDefFoundError: Trying to build
If I may I will explain how the powers that be where I am
[Book] isbn(PK),title,category_id,subcategory_id,price [Author] isbn(FK),author_id(PK),name [Category] category_id(PK),name [SubCategory] sub_category_id(PK),category_id(FK),name I have a database (not designed
Title is the entire question. Can someone give me a reason why this happens?
Title says it mostly. I want to add a simple extension method to the
Title field is sealed. Any attempts to update the default value resets the value

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.