qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] Coding style for errors


From: Lluís Vilanova
Subject: Re: [Qemu-devel] Coding style for errors
Date: Thu, 22 Oct 2015 15:30:34 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.5 (gnu/linux)

Markus Armbruster writes:

> Lluís Vilanova <address@hidden> writes:
[...]
>> So, is there any agreement on what should be used? If so, could that please 
>> be
>> added to CODING_STYLE?

> I think HACKING would be a better fit.

What about this? (at the end of HACKING) Feel free to add references to other
functions you think are important. I'll send a patch once we agree on the text.

Cheers,
  Lluis


7. Error reporting

QEMU provides two different mechanisms for reporting errors. You should use one
of these mechanisms instead of manually reporting them (e.g., do not use
'printf', 'exit' or 'abort').

7.1. Errors in user inputs

QEMU provides the functions in "include/qemu/error-report.h" to report errors
related to inputs provided by the user (e.g., command line arguments or
configuration files).

These functions generate error messages with a uniform format that can reference
a location on the offending input.

7.2. Other errors

QEMU provides the functions in "include/qapi/error.h" to report other types of
errors.

Functions in this header are used to accumulate error messages in an 'Error'
object, which can be propagated up the call chain where it is finally reported.

7.3. Errors with an immediate exit/abort

There are two convenience forms to report errors in a way that immediately
terminates QEMU:

* 'error_setg(&error_fatal, msg, ...)'

  Reports a fatal error with the given error message and exits QEMU.

* 'error_setg(&error_abort, msg, ...)'

  Reports a programming error with the given error message and aborts QEMU.

For convenience, you can also use 'error_setg_errno' and 'error_setg_win32' to
append a message for OS-specific errors, and 'error_setg_file_open' for errors
when opening files.


-- 
"And it's much the same thing with knowledge, for whenever you learn
something new, the whole world becomes that much richer."
-- The Princess of Pure Reason, as told by Norton Juster in The Phantom
Tollbooth



reply via email to

[Prev in Thread] Current Thread [Next in Thread]