Re: please suggest
pushkal wrote:
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.
Well, you're code doesn't compile with any compliant
compiler:-). But that is for reasons totally unrelated to the
question you are asking.
which might affect a big project too.
Big projects test, and have code review. And only throw is very
limited, documented cases.
/////////////////////////////////
#include<iostream.h>
This is an out of date header, not fully supported by most of
the compilers I use. Try:
#include <iostream>
#include <ostream>
(Most of the compilers do have a header with the name
<iostream.h>, which may contain enough to compile the code
you've written. But except for VC++, the versions I've seen
have not been adequate to compile real older code which used the
older header. At any rate, if you're learning, you really
should limit yourself to the standard headers, at least until
you really have to deal with legacy code.)
main()
And this shouldn't compile either. You simply cannot declare a
function without specifying its return type. In the case of
main, this is always int, do you must write:
int main()
{
try
{
cout<< " before throw " << endl ;
Of course, with the new headers, you'll need to write:
std::cout << "..." << std::endl ;
throw ;
And this is your question. In practice, there's really no way
for the compiler to detect the error in all cases, so the
standard doesn't require it.
The number of cases where you need a throw like this are
exceedingly rare, and almost always within an immediate catch
block. In practice, I cannot imagine such a mistake getting
through code review.
cout<< " after throw" << endl ;
}
catch ( ... )
{
cout << "inside catch "<< endl ;
}
}
//////////////////////////////////////
--
James Kanze GABI Software
Conseils en informatique orient?e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S?mard, 78210 St.-Cyr-l'?cole, France, +33 (0)1 30 23 00 34
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]