Custom error message

  • Thread starter Thread starter Andrey Dzizenko
  • Start date Start date
A

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.
 
Andrey Dzizenko said:
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
 
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.
 
Andrey Dzizenko said:
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
 
Back
Top