[Ilugc] Exception handling problem(g++)
Suriya Narayanan M S
mssnlayam at vsnl.net
Sun Jul 18 17:25:34 IST 2004
On Mon, Jul 19, 2004 at 02:59:57AM +0530, VENKATRAMAN.D at HUTCHINDIA.com wrote:
>
> int main( )
> {
> for( int i = 0; i < 3; i++ )
> {
> try {
> throwFunc( i ) ;
> }
> catch( ... ) {
> cout << "exception caught" << endl ;
> }
>
> }// for loop
>
> return( 0 ) ;
> }
>
>
> void throwFunc( int i )
> {
> int x = 5, y = 0, r = 0 ;
> r = x /y ;
> }
>
throwFunc does not ``throw'' any exception as you expect it to. C++
exceptions are different from processor exceptions. x/y raises a
division by zero exception. You should instead have
if (y == 0) {
throw EXCEPTION;
}
HTH,
Suriya
More information about the ilugc
mailing list