|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Custom error messageHi 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" <A.Dzize***@logicexplorers.com> wrote: It doesn't throw an error - it's a compiler error, so there's no user> 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". code running. > Is there any opportunity to define custom error when accessing this class The best you could do is turn it into a runtime error by making the> constructor? E.g. "This class is singleton. Use should use Instance > property to get its instance" 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. 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 > "Andrey Dzizenko" <A.Dzize***@logicexplorers.com> wrote: I understood you perfectly. You can't create a new compiler error apart> 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. from preprocessor errors like: #error "Your error message" but that only works if you want to detect #define conflicts. -- Barry |
|||||||||||||||||||||||