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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T12:18:01+00:00 2026-06-06T12:18:01+00:00

I just read in Code Complete that you should not use exceptions for flow

  • 0

I just read in Code Complete that you should not use exceptions for flow control. I also know that the common advice is to use exceptions to handle “exceptional cases.” But I’m not sure how to apply this advice. Is it a good idea to use exceptions to check for invalid parameters in a constructor? For instance, I have an ExcelInputConverter that turns rows in a spreadsheet into Record objects (for manipulation). The constructor takes the name of an excel file as input. Should I use exceptions to check that the incoming strings are valid excel files? That the excel files exist? It seems like I should use exceptions here because if this happens, the class essentially can’t function.

Is it a good idea to check for invalid data within the class or outside of the class?

Public Sub New(filename as string) 'new excel input converter
      If Not (Path.GetExtension(fileName) = ".xls" Or Path.GetExtension(fileName) = ".xlsx") Then Throw New Exception("Can't make an Excel input converter from a non-Excel file like " & inputFileName)
      If Not (File.Exists(fileName)) Then Throw New Exception("This file does not exist. Can't make an Excel converter")
  • 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-06T12:18:03+00:00Added an answer on June 6, 2026 at 12:18 pm

    If an object cannot be constructed due to an invalid argument to a constructor, an Exception is appropriate. Most languages do not provide a different means of telling the object creator that something went wrong (other than perhaps setting an “Invalid” flag on the object, which I would not suggest).

    .NET defines an ArgumentException for this type of situation.

    Is it a good idea to check for invalid data within the class or outside of the class?

    The class is in the best position to know what data is valid for it. If the class evolves over time and the rules for valid data change, you don’t want to have to go change all of the code that uses that class to reflect that change.

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

Sidebar

Related Questions

I recently read in Code Complete that the recommended way of handling expressions that
i've just read a few posts on hiding Silverlight code in some way. Main
I write a lot of Python code where I just want to read a
I just read an article on www.songho.ca which indicates that a projection matrix is
I just read a blog which says ...methods that couldn’t be inlined previously because
I know of at least two byte-code enhancer that modify the object model at
Its been a while I have ready Mcconnell's Code Complete . Now I read
I just read on this answer (answer has since been removed) and I'm sure
I just read this great answer from BalusC about how to upload files with
I just read this requirement on a job listing: Aware of the pitfalls of

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.