Hi guys,
quick question. Does the structure

try
{

}

catch

{

exit(0);
}

require the preprocessor directive

#include<cstdlib>

to be declared at the beginning of the program? The thing is if I don't declare it the visual c++ compiler works fine but if I try in Unix with g++ it doesn't compile...
thanks

Exceptions do not exist in C, so including the stdlib won't do any good.
I don't know the exact details, but maybe Visual C++ accepts 'catch' without any specification as to what you want to catch, and g++ doesn't.

In any case, I suggest you specify what exceptions you want to catch, for example:

try {
   throw 1;
} catch( int e )
{ 

}

try {
    throw std::something;
} catch( std::exception& e )
{

}

try {

} catch( ... )  // Catches every C++ exception
{

}

Hi guys,
quick question. Does the structure

try
{

}

catch

{

exit(0);
}

require the preprocessor directive

#include<cstdlib>

to be declared at the beginning of the program? The thing is if I don't declare it the visual c++ compiler works fine but if I try in Unix with g++ it doesn't compile...
thanks

You only need cstdlib for exit(0);

hi thanks, yeah that's what I thought, but I was not sure. SO the try catch itself is fine but when I get

exit(0);

I need cstdlib. Cool, thanks guys

Next time also post the compiler error(s) you're getting ;)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.