Home All Groups Group Topic Archive Search About

Custom error message

Author
11 Jul 2006 12:50 PM
Andrey Dzizenko
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.

Author
11 Jul 2006 1:48 PM
Barry Kelly
"Andrey Dzizenko" <A.Dzize***@logicexplorers.com> wrote:

> 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

Author
12 Jul 2006 8:49 AM
Andrey Dzizenko
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.



On Tue, 11 Jul 2006 17:48:55 +0400, Barry Kelly <barry.j.ke***@gmail.com> 
wrote:

Show quote
> "Andrey Dzizenko" <A.Dzize***@logicexplorers.com> wrote:
>
>> 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
>
Author
12 Jul 2006 4:01 PM
Barry Kelly
"Andrey Dzizenko" <A.Dzize***@logicexplorers.com> wrote:

> 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


AddThis Social Bookmark Button