[Spice-devel] [PATCH 12/22] Add exception handling classes
Christophe de Dinechin
christophe.de.dinechin at gmail.com
Thu Mar 1 17:06:08 UTC 2018
> On 28 Feb 2018, at 17:46, Christophe Fergeau <cfergeau at redhat.com> wrote:
>
> On Wed, Feb 28, 2018 at 04:43:15PM +0100, Christophe de Dinechin wrote:
>> From: Christophe de Dinechin <dinechin at redhat.com>
>>
>> Throwing 'runtime_error' directly should be reserved for the support
>> library. Add an 'Error' class as a base class for all errors thrown
>> by the streaming agent, as well as subclasses used to discriminate
>> between categories of error.
>>
>> The Error class offers:
>> - a 'format_message' member function that formats a message without
>> allocating memory, so that there is no risk of throwing another
>> exception at throw time.
>
> For what it's worth, if we get in an out of memory situation, the agent
> is more than likely to be dying very soon anyway (and this is true for
> most code out there in my opinion).
The point is that we get the *original* error, instead of some “bad_alloc” message thrown trying to format the error message.
Even if I’m low on memory, I’d rather have:
“unable to open file /foo/bar"
instead of:
“std::bad_alloc”
More information about the Spice-devel
mailing list