C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

why these program terminate abnormally

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ Language (Moderated)
View previous topic :: View next topic  
Author Message
kunal
Guest





PostPosted: Thu Aug 18, 2005 1:06 pm    Post subject: why these program terminate abnormally Reply with quote



Hello friends,

i just cn't understand y these program terminate abnormally.

1.

int main()
{
try
{
throw ;
cout << "Start" ;
}
catch(...)
{
cout << "Exception" ;
}
cout << "End" ;
return 0 ;
}


o/p : Abnormal program termination.



2.


class Excep
{
public:
Excep()
{
cout << "ctor"<< endl ;
}
~Excep()
{
throw 3 ;
cout << "dtor"<< endl ;
}
} ;
void Fn()
{
Excep e ;
throw 3 ;
}
int main()
{
try
{
Fn() ;
}
catch(...)
{
cout << "Exception" ;
}
return 0 ;
}


O/P : ctor abnormal program termination.

plz expalin me y this happens.

thx in advance.

regards--
kunal


[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Back to top
Kai-Uwe Bux
Guest





PostPosted: Thu Aug 18, 2005 3:44 pm    Post subject: Re: why these program terminate abnormally Reply with quote



kunal wrote:

Quote:
Hello friends,

i just cn't understand y these program terminate abnormally.

1.

int main()
{
try
{
throw ;
cout << "Start" ;
}
catch(...)
{
cout << "Exception" ;
}
cout << "End" ;
return 0 ;
}


o/p : Abnormal program termination.

Standard clause 15.1/8:

If no exception is presently being handled, executing a throw-expression
with no operand calls terminate().


Quote:


2.


class Excep
{
public:
Excep()
{
cout << "ctor"<< endl ;
}
~Excep()
{
throw 3 ;
cout << "dtor"<< endl ;
}
} ;
void Fn()
{
Excep e ;
throw 3 ;
}
int main()
{
try
{
Fn() ;
}
catch(...)
{
cout << "Exception" ;
}
return 0 ;
}


O/P : ctor abnormal program termination.


Standard clause 15.2/3:

... If a destructor called during stack unwinding exits with an exception,
terminate() is called ...


Best

Kai-Uwe Bux


[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]


Back to top
Hyman Rosen
Guest





PostPosted: Thu Aug 18, 2005 3:45 pm    Post subject: Re: why these program terminate abnormally Reply with quote



kunal wrote:
Quote:
i just cn't understand y these program terminate abnormally.
int main() { try { throw ;

You are trying to rethrow an exception, but there is no exception
to rethrow, so as per 15.1/8, terminate() is called.

Quote:
struct Excep { ~Excep() { throw 3 ; } } ;
void Fn() { Excep e ; throw 3 ; }
int main() { try { Fn() ; }

When Fn throws 3, it unwinds the stack and thus calls Excep::~Excep()
which also throws 3. As per 15.5.1, when the destructor of an object
being destroyed by stack unwinding exits with an exception, terminate()
is called.

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]


Back to top
Alf P. Steinbach
Guest





PostPosted: Thu Aug 18, 2005 3:46 pm    Post subject: Re: why these program terminate abnormally Reply with quote

* kunal:
Quote:
[homework with specially crafted example code]

See FAQ item 5.2,
<url: http://www.parashift.com/c++-faq-lite/how-to-post.html#faq-5.2>.

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]


Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ Language (Moderated) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.