diff --git a/doc/src/content/motivation/_index.md b/doc/src/content/motivation/_index.md new file mode 100644 index 00000000000..a3659f79d22 --- /dev/null +++ b/doc/src/content/motivation/_index.md @@ -0,0 +1,17 @@ ++++ +title = "Motivation" +weight = 8 ++++ + +This section describes techniques currently used to report and handle failures +in functions, it also shows why this techniques might be insufficient. + +If you just want to learn how to use Outcome library go straight to [Tutorial +section](../tutorial). + +{{% notice note %}} +Motivation section of this documentation is not complete yet. +{{% /notice %}} + + +{{% children description="true" depth="1" %}} diff --git a/doc/src/content/motivation/exceptions.md b/doc/src/content/motivation/exceptions.md new file mode 100644 index 00000000000..e5b8d62bb17 --- /dev/null +++ b/doc/src/content/motivation/exceptions.md @@ -0,0 +1,31 @@ ++++ +title = "Exceptions" +description = "Exceptions with their good and bad sides." +weight = 10 ++++ + +## Exceptions + +Exceptions are the default mechanism in C++ for reporting, propagating and +processing the information about function failures. Their main advantage is +the ability to describe the "success dependency" between functions: if you want to +say that calling function `g()` depends on the successful execution of function `f()`, +you just put `g()` below `f()` and that's it: + +```c++ +int a() +{ + f(); + g(); // don't call g() and further if f() fails + return h(); // don't call h() if g() fails +} +``` + +In the Standard C++ terms this means that `f()` is *sequenced before* `g()`. +This makes failure handling extremely easy: in a lot of cases you do not have +to do anything. + +But there is also cost to be paid when using exceptions. + +This tutorial is in the process of being written. Once done we will explain in detail +why it is sometimes beneficial not to use exceptions to signal failures. diff --git a/doc/src/content/tutorial/result/try.md b/doc/src/content/tutorial/result/try.md index 9d504f915de..fdaf980d91f 100644 --- a/doc/src/content/tutorial/result/try.md +++ b/doc/src/content/tutorial/result/try.md @@ -8,7 +8,7 @@ tags = ["try"] In the implementation of function `print_half` we have seen the usage of the macro {{< api try OUTCOME_TRY >}}: ```c++ -OUTCOME_TRY (i, (BigInt::fromString(text))); +OUTCOME_TRY (i, BigInt::fromString(text)); ``` The `OUTCOME_TRY` macro uses C macro overloading to select between two implementations based on the number of diff --git a/doc/src/snippets/intro_example.cpp b/doc/src/snippets/intro_example.cpp index e4a774065a3..711847f2cc5 100644 --- a/doc/src/snippets/intro_example.cpp +++ b/doc/src/snippets/intro_example.cpp @@ -37,7 +37,7 @@ auto process(const string& content) noexcept auto get_int_from_file(string_view path) noexcept -> outcome::result { - OUTCOME_TRY(str, (read_data_from_file(path))); + OUTCOME_TRY(str, read_data_from_file(path)); // if control gets here read_data_from_file() has succeeded return process(str); // decltype(str) == string } diff --git a/doc/src/snippets/using_result.cpp b/doc/src/snippets/using_result.cpp index bab05fa2d2f..06a8b068c8e 100644 --- a/doc/src/snippets/using_result.cpp +++ b/doc/src/snippets/using_result.cpp @@ -125,7 +125,7 @@ outcome::result print_half(const std::string& text) { if (r.error() == ConversionErrc::TooLong) // #3 { - OUTCOME_TRY (i, (BigInt::fromString(text)));// #4 + OUTCOME_TRY (i, BigInt::fromString(text)); // #4 std::cout << i.half() << std::endl; } else