Re: please suggest
pushkal wrote:
I am new to this group, not to mention with a miniscule knowledge on
C++.
You should read the FAQ and pick a topic that resembles your problem.
This Silly piece of code ( coded by me) aborts on execution.
offcourse this has no exception object to be thrown.
Please suggest is there a technique to stop such a bad code from
compiling. which might affect a big project too.
[...]
#include<iostream.h>
Many compilers will already stop compiling here, because that header is not
part of standard C++ and thus only sometimes included for backward
compatibility.
main()
Many more will stop here, because an implicit int returntype has never
existed in C++.
{
try
{
cout<< " before throw " << endl ;
throw ;
cout<< " after throw" << endl ;
}
catch ( ... )
{
cout << "inside catch "<< endl ;
}
}
Trying to rethrow an exception without being in a catch handler is not
necessarily possible at compile-time, consider this rethrow statement was
in a function that might be called in different contexts. It would take a
lot of effort to detect that.
Also, I think the semantics are well-defined for this case to invoke abort()
or a similarly non-graceful way of terminating or invoking the debugger,
there is nothing wrong about this.
Lastly, looking at the code (in particular the two points that should have
kept it from compiling) it seems to me that you should a) update your
compiler to anything even halfway modern and b) that you should update your
C++ knowledge. For the former, it depends on your platform, for the latter
you should pick a good book from the reviews at http://accu.org.
cheers
Uli
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]