diff options
author | James Henderson <jh7370@my.bristol.ac.uk> | 2019-02-01 10:02:42 +0000 |
---|---|---|
committer | James Henderson <jh7370@my.bristol.ac.uk> | 2019-02-01 10:02:42 +0000 |
commit | fb3ca132b12f7a3899b74e6a79d961201c7d9cfe (patch) | |
tree | 50d0fbc02e7f086fa3549c79f7706e82875aaf81 /llvm/docs/ProgrammersManual.rst | |
parent | 758657e56550c0681260bb61b0a2bddb4a5c2e6d (diff) | |
download | bcm5719-llvm-fb3ca132b12f7a3899b74e6a79d961201c7d9cfe.tar.gz bcm5719-llvm-fb3ca132b12f7a3899b74e6a79d961201c7d9cfe.zip |
[doc]Update String Error documentation in Programmer Manual
A while back, createStringError was added to provide easier construction
of StringError instances, especially with formatting options. Prior to
this patch, that the documentation only mentions the standard method of
using it. Since createStringError is slightly shorter to type, and also
provides the formatting options, this patch updates the Programmer's
Manual to use the new function in its examples, and to mention the
printf formatting options. It also fixes a small typo in one of the
examples and removes the unnecessary make_error_code call.
llvm-svn: 352846
Diffstat (limited to 'llvm/docs/ProgrammersManual.rst')
-rw-r--r-- | llvm/docs/ProgrammersManual.rst | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/llvm/docs/ProgrammersManual.rst b/llvm/docs/ProgrammersManual.rst index 94555d9d4ff..e2cb14b4240 100644 --- a/llvm/docs/ProgrammersManual.rst +++ b/llvm/docs/ProgrammersManual.rst @@ -656,19 +656,21 @@ taken is to report them to the user so that the user can attempt to fix the environment. In this case representing the error as a string makes perfect sense. LLVM provides the ``StringError`` class for this purpose. It takes two arguments: A string error message, and an equivalent ``std::error_code`` for -interoperability: +interoperability. It also provides a ``createStringError`` function to simplify +common usage of this class: .. code-block:: c++ - make_error<StringError>("Bad executable", - make_error_code(errc::executable_format_error")); + // These two lines of code are equivalent: + make_error<StringError>("Bad executable", errc::executable_format_error); + createStringError(errc::executable_format_error, "Bad executable"); If you're certain that the error you're building will never need to be converted to a ``std::error_code`` you can use the ``inconvertibleErrorCode()`` function: .. code-block:: c++ - make_error<StringError>("Bad executable", inconvertibleErrorCode()); + createStringError(inconvertibleErrorCode(), "Bad executable"); This should be done only after careful consideration. If any attempt is made to convert this error to a ``std::error_code`` it will trigger immediate program @@ -677,6 +679,14 @@ interoperability you should look for an existing ``std::error_code`` that you can convert to, and even (as painful as it is) consider introducing a new one as a stopgap measure. +``createStringError`` can take ``printf`` style format specifiers to provide a +formatted message: + +.. code-block:: c++ + + createStringError(errc::executable_format_error, + "Bad executable: %s", FileName); + Interoperability with std::error_code and ErrorOr """"""""""""""""""""""""""""""""""""""""""""""""" |