[Spice-devel] [PATCH 12/22] Add exception handling classes

Christophe Fergeau cfergeau at redhat.com
Thu Mar 8 10:22:23 UTC 2018


On Thu, Mar 08, 2018 at 10:56:55AM +0100, Christophe de Dinechin wrote:
> > In many cases you want to add information to the exception and
> > is quite common to catch one exception, add another informations
> > and throw a more detailed exception.
> 
> It is useful, indeed. And when you need to do that, I strongly prefer something like:
> 
> catch (WriteError &we) {
> 	if (errno == EPERM) {
> 		collect_SELinuxData(&sedata);
> 		throw WriteErrorWithSELinuxData(we, sedata);
> 	}
> }
> 
> which I find vastly superior to an alternative like:
> 
> catch (some_runtime_error &e) {
> 	if (parse_what_looking_for_errno(e.what()) == EPERM) {
> 		collect_SELinuxData(&sedata);
> 		throw some_runtime_error(e.what() + “ with SELinux information “ + format_se_linux_info_as_string(sedata));
> }

I believe you are missing the point, right now the discussion is not
about the Exception hierarchy, the constructor API, ..., it's only about
the 'const char *' args to the constructor(s) having to be kept alive by
the caller rather than having the exception class taking care of this.

Once that is taken care of, there might be more discussion about the
structure of the exception hierarchy, which constructors we want, ...
but as of now, this is not the blocking point, so let's not diverge in
that discussion just yet.

Christophe
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <https://lists.freedesktop.org/archives/spice-devel/attachments/20180308/5ae2b939/attachment.sig>


More information about the Spice-devel mailing list