First I found in cplusplus.com the following quote:
The catch format is similar to a regular function that always has at least one parameter.
But I tried this:
try
{
int kk3,k4;
kk3=3;
k4=2;
throw (kk3,"hello");
}
catch (int param)
{
cout << "int exception"<<param<<endl;
}
catch (int param,string s)
{
cout<<param<<s;
}
catch (char param)
{
cout << "char exception";
}
catch (...)
{
cout << "default exception";
}
The compiler doesn't complain about the throw with braces and multiple arguments. But it actually complains about the catch with multiple parameters in spite of what the reference said. I'm confused. Does try
and catch
allow this multiplicity or not? And what if I wanted to throw an exception that includes more than one variable with or without the same type.