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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T05:13:44+00:00 2026-05-11T05:13:44+00:00

I have a case in which I have to read an input file in

  • 0

I have a case in which I have to read an input file in the C’tor, but sometimes this file doesn’t exist. This object is usually held statically, so its C’tor is called while loading the dll. I can’t catch the exception I throw if the file doesn’t exist because it’s too early, and my executable crashes in an ugly way. I know it’s bad practice to throw exceptions out of a C’tor, but I can’t go on if the file doesn’t exist, so I have to. Is there a way to catch the exception while loading the dll, and if not, is there any better solution for this scenario?

Thanks, Gal

  • 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-11T05:13:45+00:00Added an answer on May 11, 2026 at 5:13 am

    I assume the static object has the file scope (it is outside any function/class definition). You may consider moving it to an accessor function and accessing it only via that function, like this:

    class Object; Object& getObject() {     static Object object;     return object; } 

    The static instance of Object will be initialized upon the first calling of the getObject() method. If the Object‘s constructor throws, you can easily catch the exception. Just you need to remember wrapping every call of getObject() into a try/catch block (or suffer from the exception bubbling up the stack chain); that may be a bit inconvenient, but on the other hand you may decide to wrap just the logically ‘first’ call, if you know which one it is in the program logic flow.

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

Sidebar

Related Questions

I have a pretty simple case which I started solving using foreach(), but then
I have a Boost unit test case which causes the object under test to
My program allows the user to specify a file which is read as input,
I have read a number of posts about this but none with any solid
I have to read a text file which can begin with optional comments. In
I have a 200+ case statement in Classic ASP which is getting out of
I have a Lucene index which is currently case sensitive. I want to add
I have the following use case , lot of code which was tightly coupled
Ok, I've tried to read up on this but I'm stumped. Unfortunately it's a
I have a input XML like this : <in_xml> <company> <project> ProjNo1 ProjNo2 ProjNo3

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.