?
Slides configuration
Slide Notes:
Hide
On Slide
On Separate Page
Merge Fragments
Show Slide Numbers
Apply
Reset
How to save slides as pdf?
Open the print dialog.
Change
Destination
to
Save to PDF
.
Change
Layout
to
Landscape
.
Change
Margins
to
None
.
Disable
Print headers and footers
option.
Enable
Print backgrounds
option.
Click the
Save
button.
Choose a filename and destination.
# C/C++ Programming ## Labo 3 --- ```mermaid kanban column1[Content] task1[Clang-tidy bugprone-exception-escape] task2[Using the vscode debugger] task3[STL containers exercises] task4[Error handling exercises] ``` --- ## Devcontainer
--- * Similar to labo 2 devcontainer. * Uses a src subdirectory. * Has a cpprog module with expect() function. * See [README.md](https://gitlab.apstudent.be/cpp-programming/devcontainer-labo-3/-/blob/main/README.md) file in git repository. --- ```c++ import cpprog; int my_division(int numerator, int denominator) { cpprog::expect([&]{ return denominator != 0; }, "cannot divide by zero"); return numerator / denominator; } ``` Note: * How to use the expect() function for pre-conditions? * See also hello-contracts example in devcontainer. --- ## Clang-tidy ### bugprone-exception-escape --- Finds functions which may throw an exception directly or indirectly, but they should not. The functions which should not throw exceptions are the following: Note: *
--- * Destructors * Move constructors * Move assignment operators * The main() functions * swap() functions * iter_swap() functions * iter_move() functions * Functions marked with throw() or noexcept * Other functions given as option Note: * When an exception escapes the main function, the application crashes. * Don't worry about the other functions yet. 😉 --- ### Solution Catch exceptions in the main function! --- ```c++ [] using std; int main() try { // ... return 0; } catch (std::exception const& e) { std::cerr << e.what() << '\n'; return 1; } ``` Note: * Print error message to the console error stream (STDERR). * Return 0 for success. * Return 1 for failure. * This is a convention. --- ## Debugger demo Note: * breakpoints * step, resume * variable watch * call stack (will be covered in a later session) ---
--- ## Exercises See digitap.