Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / New Users / July 2006

Tip: Looking for answers? Try searching our database.

Custom error message

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Andrey Dzizenko - 11 Jul 2006 13:50 GMT
Hi all!

I have a singleton-class with private constructor and Instance property.  
It's clear that access to this class should be got by using this property.
"new Class()" construction is incorrect and throws an error "can't access  
due to its protection level".

Is there any opportunity to define custom error when accessing this class  
constructor? E.g. "This class is singleton. Use should use Instance  
property to get its instance"

Thank you in advance.

A. Dzizenko.
Barry Kelly - 11 Jul 2006 14:48 GMT
> I have a singleton-class with private constructor and Instance property.  
> It's clear that access to this class should be got by using this property.
> "new Class()" construction is incorrect and throws an error "can't access  
> due to its protection level".

It doesn't throw an error - it's a compiler error, so there's no user
code running.

> Is there any opportunity to define custom error when accessing this class  
> constructor? E.g. "This class is singleton. Use should use Instance  
> property to get its instance"

The best you could do is turn it into a runtime error by making the
constructor public. I don't think that would be an improvement, though.

-- Barry

Signature

http://barrkel.blogspot.com/

Andrey Dzizenko - 12 Jul 2006 09:49 GMT
I've spoken incorrectly. It's a compiler error. I want to redefine a  
compiler error.

Making constructor public is bad idea. We can't access to the constructor  
directly because of a sigleton.

>> I have a singleton-class with private constructor and Instance property.
>> It's clear that access to this class should be got by using this  
[quoted text clipped - 15 lines]
>
> -- Barry
Barry Kelly - 12 Jul 2006 17:01 GMT
> I've spoken incorrectly. It's a compiler error. I want to redefine a  
> compiler error.
>
> Making constructor public is bad idea. We can't access to the constructor  
> directly because of a sigleton.

I understood you perfectly. You can't create a new compiler error apart
from preprocessor errors like:

 #error "Your error message"

but that only works if you want to detect #define conflicts.

-- Barry

Signature

http://barrkel.blogspot.com/


Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.