How to reply, "Sorry, couldn't create that class"

Posted on 2011-10-11
Last Modified: 2012-05-12
I'm old fashioned procedure programmer still transitioning. I had this idea for a log file I'd create a class LogFile, then do
logFile = new LogFile();

Open in new window

and but then what do I do if there's a problem opening the log file? How do I say, "Sorry, couldn't create that class, there was a problem."?
Question by:deleyd
    LVL 7

    Accepted Solution

    a) First of all, you shouldn't be trying to open a file within the constructor of a class (or for that matter, do anything whatsoever other than create the object and perform some very conservative initialization).
    b) There are many ways to "say" there is a problem.  You could throw an exception, use an assert, create a pop-up window, etc.

    If you must do it in line 1 above, then write the code in the class's constructor.

    Author Closing Comment

    Don't do it in the constructor.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    Article by: Ivo
    Anonymous Types in C# by Ivo Stoykov Anonymous Types are useful when  we do not need to follow usual work-flow -- creating object of some type, assign some read-only values and then doing something with them. Instead we can encapsulate this read…
    Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
    Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    734 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now