12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- <chapter xml:id="throw_errno.h">
- <title><tt>__vic/throw_errno.h</tt></title>
- <chapter xml:id="throw_errno">
- <title><tt>throw_errno()</tt></title>
- <code-block lang="C++"><![CDATA[
- [[noreturn]] void throw_errno(const char *prompt);
- [[noreturn]] void throw_errno(const char *prompt, int err_no);
- ]]></code-block>
- <p>Throw an exception with global <tt>errno</tt> value or given
- <tt>err_no</tt> correspondingly. Default exception type is
- <xref to="libc_error"/> at the moment but can be changed at link time
- by overriding this functions. For example <tt>std::system_error</tt> can be
- used. Just create cpp-file with the following content in your project:</p>
- <code-block lang="C++"><![CDATA[
- #include<__vic/throw_errno.h>
- #include<system_error>
- //----------------------------------------------------------------------------
- // Override library functions to throw std::system_error
- //----------------------------------------------------------------------------
- void __vic::throw_errno(const char *prompt, int err_no)
- {
- throw std::system_error(err_no, std::system_category(), prompt);
- }
- //----------------------------------------------------------------------------
- ]]></code-block>
- <p>It's enough to override only one functions because the second one just calls
- <tt>throw_errno(prompt, errno)</tt>.</p>
- <section><title>Example</title>
- <code-block lang="C++"><![CDATA[
- ssize_t written = ::write(fd, buf, buf_size);
- if(written < 0) __vic::throw_errno("write");
- // ...
- ]]></code-block>
- </section>
- </chapter>
- </chapter>
|