If I had to make a guess on why exceptions don't support implicit conversions is because it would be very difficult to do.
Implicit conversions for functions are realitively easy thing for a compiler to do. This function needs a Class A, but you gave it Class B, but A can be constructed from B. Now consider the following code example.
In this situation the compilier is going to have to go three functions deep to see you are going to throw a string and then do the implicit conversion. This example is really simple, consider what would happen if this was a real application. The compiler could be 50 functions deep across multiple source files.
Implicit conversions for functions are realitively easy thing for a compiler to do. This function needs a Class A, but you gave it Class B, but A can be constructed from B. Now consider the following code example.
Code:
class Error
{
public:
Error(string c){cout << c;};
};
void c()
{
throw string("HELP");
}
void b()
{
c();
}
void a()
{
b();
}
int main()
{
try
{
a();
}
catch(Error err)
{
}
}
Comment