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

The Archive Base Latest Questions

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

When starting my application, I have a couple of classes which are required to

  • 0

When starting my application, I have a couple of classes which are required to read certain files in order to create a set of default data.

The logical place (to me) to do this is in a Shared class constructor; the idea would be to throw a class-level event if the reading of the defaults file fails. Unfortunately, this does not work as attempting to access such an event, in order to attach a handler to it, fires the class constructor before the event has been attached. In a failing case, the constructor starts, fires the fail event, the constructor completes, and then the event handler is attached, after the event has fired.

The only other solution I can think of is to give the class a ‘typeInitialisedSuccessfully’ boolean property and put a try/catch block around every call to construct an instance of the class, which seems unnecessarily kludgey to me.

Can someone suggest a more elegant solution?

EDIT: Because this is a fundamental Class, used in one form or another across nearly all of our software tools, I would greatly prefer a solution that will notify future programmers that the type initialiser needs to be called, which is why I initially went towards the Shared Constructor as a solution.

  • 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-11T11:44:26+00:00Added an answer on May 11, 2026 at 11:44 am

    I would suggest having an Init (can be static) method on your classes. You would run this method on your application start for each of your classes-to-be-initialized. In that case you can wrap it in try catch and act accordingly.

    Re your edit: Generally throwing exceptions in places like shared constructor is bad idea – you can’t really catch it, it’s hard to predict when the init will be called etc.

    In case you specify I’d add either IsInitialized field that would be checked and an exception thrown when calling method/property that requires it. It can get tedious though.

    The other option I would go for might be far from your current architecture. In many IoC tools they use concept of Startable (castle, autofac) – i.e. you specify an interface with a start method and the IoC will make sure the method runs at specified time (most likely when application is started). You would do your error handling in your ‘Start’ method and bubble up whatever wrapped exception with all the detailed information. I could elaborate on this but I have feeling it’s not really the way you would go.

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

Sidebar

Related Questions

I have an application in which I am starting a timer for two task:
I am starting a web application project that will have an Adobe Flex front-end
I have a live facebook application. Starting from last week, I keep getting PHP
Possible Duplicate: Stopping & Starting music on incoming calls I have a simple application
Is it possible to start service without starting application? I need to refresh data
I am starting a Facebook application with a couple of friends. What good, free,
I have an x86 Windows application that consists of a couple of services and
I'm just starting with distributed application development. I need to create (all by myself)
I have a couple of simple tests, like assertNotNull(mActivity); (I'm reading M.D.Torres Android Application
I have a couple of XML files that are used to control unattended installations

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.