@
dhayden
Hi,
Just a question to help my education a little. It's always good for dabblers like me to get insight from a professional programmer :+D
My main reason for asking about this is that constructors and overloaded operators cannot return anything.
In your environment, could you still
throw
from a constructor so that the object isn't created thus avoiding having an invalid object? To avoid the exception being propagated, I guess one would have to avoid having constructor arguments that create other objects that in turn might fail. In other words, create objects first, if that works then use them as arguments in a constructor call. Would this be a valid use of an exception in your environment?
- The right way to handle an error is different in each place where an error occurs. Put another way, some people complain that return codes create a nightmare, but the reality is that you need the code to handle each case anyway. |
I can't help thinking that one would throw different exceptions to cover each case. Is this nearly the same thing? Or am I looking at it wrongly?
- Often an error happens in some low level function and you have to deal with it much higher up in the call stack. ....... |
I can see how it would be a pain to invent some kind of exception class to cover every possibility, with the idea that new info is added to it as it passed upwards - I wonder if it would be better if C++ allowed throw with multiple arguments? That way it would be easier to have a diagnostic like
"xyz client can't contact config server when trying to get configuration value QRS: call timed out." |
Just an idea - no clues on how good it is or how well it would fly.
Hope all is well at your end :+)