I'm struggling with a very simple question:
I'm now working on a server application, and I need to invent a hierarchy for the exceptions (some exceptions already exist, but a general framework is needed). How do I even start doing this?
I'm thinking of following this strategy:
1) What is going wrong?
- Something is asked, which is not allowed.
- Something is asked, it is allowed, but it does not work, due to wrong parameters.
- Something is asked, it is allowed, but it does not work, because of internal errors.
2) Who is launching the request?
- The client application
- Another server application
3) Message handing : as we are dealing with a server application, it's all about receiving and sending messages. So what if the sending of a message goes wrong?
As such, we might get following exception types:
- ServerNotAllowedException
- ClientNotAllowedException
- ServerParameterException
- ClientParameterException
- InternalException (in case the server does not know where the request is coming from)
- ServerInternalException
- ClientInternalException
- MessageHandlingException
This is a very general approach to define exception hierarchy, but I'm afraid that I might be lacking some obvious cases. Do you have ideas on which areas I'm not covering, are you aware of any drawbacks of this method or is there a more general approach to this kind of question (in the latter case, where can I find it)?
Thanks in advance
catch
blocks I use, I don't have much more use for the exception than what error message it contains. I don't really have anything different I can do for an exception involved in failing to read a file as one failing to allocate memory during the process of reading it, so I tend to just catchstd::exception
and report the error message it contains, maybe decorating it with"Failed to open file: %s", ex.what()
to a stack buffer before printing it.catch
blocks in a single recovery site, but often it's just to ignore the message inside the exception and print a more localized message...