Re: [Dev-C++] Creating a basic exception class
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Teodorescu C. <te...@xt...> - 2002-07-30 08:04:21
|
Daniel Glenfield wrote:
>
> Hi everyone,
> I want to create a basic exception class so my constructors can throw
> objects if they fail. Constructors will be the only things that throw
> exceptions, but the class will most likely be expanded in the future
> so other functions can throw.
>
> What do I need to include in an exception class? I think an error log
> text file would be good (I've done them before using ofstream objects)
> but what data members should the file have? I've not done these before
> so any suggestions would be great.
this is my exception class and usually i have a function that write
exception and time stamp into a log file
class Exception{
int no /*<0*/
string msg /*Optional */
string GetMessage(int no);//get the message for that exception from
a file .... use when multiple languages
string function /* only in debug mode function who throw exception */
}
how to use it
function dummy (int x )
{
if (x<0){
Exception x;
x.no=-10;
x.function=dummy
throw x;
};
}
function dummy2 ( ...)
{
try {
dummy(-1)
}catch(Exception ex){
//do clean up
//log and ...
};
};
if you use it in classes constructor
....
try {
//here constructor is called;
my_class a;
}catch(Exception x)
{
};
Don't try this.
Don't throw exception in constructor;
I ussualy use a tricky way
My class have function init who throw exception.
and if this fail ... cleanup and stuff.
>
> Daniel
>
>
> _________________________________________________________________
> Send and receive Hotmail on your mobile device: http://mobile.msn.com
>
>
>
> -------------------------------------------------------
> This sf.net email is sponsored by: Dice - The leading online job board
> for high-tech professionals. Search and apply for tech jobs today!
> http://seeker.dice.com/seeker.epl?rel_code=31
> _______________________________________________
> Dev-cpp-users mailing list
> Dev...@li...
> TO UNSUBSCRIBE: http://www.noicys.cjb.net/devcpp/ub.htm
> https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
|