I am new to C++, so sorry for asking very silly questions but I am confused with the throw statements in Exception Handling mechanism of C++.
- In the below code why do we call a function with name matching the class name?
- Is it a constructor?
- Is it creating an instance of
class Except
?
I am not understanding the syntax there.
class A
{
public:
class Except{};
void foo() { throw Except(); }
};
int main()
{
A a;
try
{
a.foo();
}
catch(Except E)//exception handler
{
cout << "Catched exception" << endl;
}
}
Except
using the default constructor, which takes no arguments. – Wheelockcatch(const Except & E)
– Farming