N
Neelesh Bodas
Hello all,
Just wanted a small clarification on these two points :
1) The following code compiles well -
int f() try {
throw "xyz";
}
catch(...)
{
}
What is expected to be the return value (I am asking about _value_, not
_type_ ) of f()? Is it undefined , implementation defined or std
defined?
Basically what happens to the return value if a function-level try
block throws an exception and the exception is caught at the same level
(and there is no return statement anywhere)?
2) When a ctor throws an exception and the exception is handelled at
the same level, does that mean that the object gets constructed
completely?
#include <iostream>
class X {
public:
X() try
{
throw 100;
}
catch(...)
{
}
};
int main()
{
X x;
std::cout << "main" << std::endl;
// I observe that this line doesnot get executed even when the
exception is caught in the ctor itself.
//I also see that the this exception gets caught in the catch(...)
handler of the constructor AND it _also_ gets propogated to main, and
it _can again_ be caught by putting the necessary catch block in main
!!!
}
What is the exact reason?
Just wanted a small clarification on these two points :
1) The following code compiles well -
int f() try {
throw "xyz";
}
catch(...)
{
}
What is expected to be the return value (I am asking about _value_, not
_type_ ) of f()? Is it undefined , implementation defined or std
defined?
Basically what happens to the return value if a function-level try
block throws an exception and the exception is caught at the same level
(and there is no return statement anywhere)?
2) When a ctor throws an exception and the exception is handelled at
the same level, does that mean that the object gets constructed
completely?
#include <iostream>
class X {
public:
X() try
{
throw 100;
}
catch(...)
{
}
};
int main()
{
X x;
std::cout << "main" << std::endl;
// I observe that this line doesnot get executed even when the
exception is caught in the ctor itself.
//I also see that the this exception gets caught in the catch(...)
handler of the constructor AND it _also_ gets propogated to main, and
it _can again_ be caught by putting the necessary catch block in main
!!!
}
What is the exact reason?