From 3caf7c2e20bcd065961945c5f65be9c09c072ef3 Mon Sep 17 00:00:00 2001 From: Erica Bugden Date: Mon, 8 Jul 2024 14:20:32 -0400 Subject: [PATCH] Docs: CodingStyle: Move error management guidelines to separate section MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Move error management guidelines to separate section to group and highlight them in the coding style. Change-Id: I0d0ba0f8ea8a4c74c73bb28217a81b4efeb9a35f Signed-off-by: Erica Bugden Signed-off-by: Jérémie Galarneau --- CodingStyle.md | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/CodingStyle.md b/CodingStyle.md index 193880879..967fbf106 100644 --- a/CodingStyle.md +++ b/CodingStyle.md @@ -141,6 +141,17 @@ ffc::grapefruit::grapefruit() } ``` +### Error management + +* Use RAII wrappers when managing system resources or interacting with C libraries. + + In other words, don't rely on ``goto``s and error labels to clean up as you would do in C. + +* Throw an exception when there's an unexpected, exceptional condition, + [including from a constructor](https://isocpp.org/wiki/faq/exceptions#ctors-can-throw), instead of returning a status code. + + However, be mindful of the exception-safety of your users. For instance, `liblttng-ctl` exposes a C interface meaning that is must catch and handle all exceptions, most likely by returning a suitable error code. + ### File layout example ```cpp @@ -252,15 +263,6 @@ Here are a couple of reminders: For example, use `|` as a bitwise or logical-or, not as a shell-style pipe. -* Use RAII wrappers when managing system resources or interacting with C libraries. - - In other words, don't rely on ``goto``s and error labels to clean up as you would do in C. - -* Throw an exception when there's an unexpected, exceptional condition, - [including from a constructor](https://isocpp.org/wiki/faq/exceptions#ctors-can-throw), instead of returning a status code. - - However, be mindful of the exception-safety of your users. For instance, `liblttng-ctl` exposes a C interface meaning that is must catch and handle all exceptions, most likely by returning a suitable error code. - * Accept a by-value parameter and move it (when it's moveable) when you intend to copy it anyway. You can do this with most STL containers. ## Python -- 2.39.5