[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now


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

Posted on 2011-10-11
Medium Priority
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

Accepted Solution

Bill Nolan earned 2000 total points
ID: 36953744
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

ID: 36954395
Don't do it in the constructor.

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Loops Section Overview
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Suggested Courses

834 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