Udemy
    •  
    •  
    •  
    •  
    •  
    •  
    •  
    •  
Turn what you know into an opportunity and reach millions around the world.
Learn More
Your cart is empty.
Keep shopping
C++ Exceptions Handling
Rating: 4.1 out of 5(31 ratings)
10,352 students

C++ Exceptions Handling

All about exceptions handling and safety in C++
Created byAndrzej Sz.
Last updated 7/2023
English

What you'll learn

  • Learn and/or refresh C++ exceptions syntax
  • Know how to throw and catch exceptions and what their limitations are
  • Discover pitfalls of throwing in constructors and destructors
  • Understand how stack unwinding works and why it's important to exceptions
  • How to create and throw/re-throw user-defined and standard exceptions
  • Dynamic exceptions specification, noexcept specifier and noexcept operator
  • Learn about exception safety guarantees
  • How to reason about exception safety of your code

Course content

8 sections35 lectures3h 48m total length
  • Throwing and catching exceptions8:53

    Learn to throw and catch exceptions in C++, using try blocks, catch clauses, and by value or by reference handling; explore int, user-defined types, and pointers.

  • Exception matching and inheritance5:38

    the video explains c++ exception handling, showing how concrete and base exceptions are matched by catch-block order, why concrete must come first, and that catch-all is placed at the end.

  • Throw and catch restrictions5:18

    Learn the three restrictions on C++ exception handling: cannot throw or catch incomplete types; cannot catch an abstract type by value; catch-by-reference works for complete types.

  • Exceptions and multiple inheritance5:54

    Explore how exceptions and multiple inheritance interact in C++ by building custom exception types that inherit from std::exception, showing how virtual inheritance removes ambiguity so a combined exception is catchable.

  • Exception object8:55

    Understand how exception objects are created, copied, and destroyed, with copy and move constructors and temporary objects. Learn why catching by reference prevents slicing and minimizes copies.

  • Stack unwinding6:12

    Understand how stack unwinding starts when an exception is thrown, how automatic objects are destroyed in reverse construction order, and how try and catch blocks guide program control flow.

  • Throwing from constructors and destructors8:35

    Explore when to throw from constructors to signal object creation, delegated constructors, how stack unwinding affects object lifetime and destructor calls, and why throwing from destructors leads to termination.

  • Real-world examples using exceptions3:37

    Explore real-world C++ exceptions by inspecting open source projects and examining how exceptions are thrown and caught, including io base failure, runtime errors, and user defined exceptions.

  • Throwing and catching exceptions

Requirements

  • Basic knowledge of C++
  • Compiler supporting at least C++11
  • Interest in C++

Description

While writing and running software, sooner or later exceptions or some other form of errors are unavoidable, whether expected or not, resulting from issues in our code or user actions, etc. Hence, we must be prepared for exceptions / errors and know how to handle them properly (whether gracefully or failing fast) to recover from or at least not exacerbate problems in our programs, including those written in languages like C++.

So, if you’ve just learned the basics of C++ and haven’t dived into exceptions yet or worked with C++ for a while but need to brush up on exceptions, then this course is for you. It’s about exceptions handling in C++, including theory, syntax and best practices. The course covers C++ standards 11-17.


By the end of this course you will learn

  • Throwing and catching exceptions and their limitations;

  • Stack unwinding;

  • Pitfalls when throwing in constructors and destructors;

  • Re-throwing and nested exceptions;

  • User-defined and standard exceptions;

  • Dynamic exceptions specification;

  • Noexcept specifier and noexcept operator;

  • Recommendations on error handling from C++ Core Guidelines.

Moreover, and probably most importantly, you will learn how to reason about exception safety of your code and exception safety guarantees, a concept that will help you write robust code in C++ and other similar languages.


So what exactly is covered in the course?

  • Lectures with code examples and explanations;

  • Summaries in PDF files from each lecture for those who prefer reading and to be able to quickly to back to specific topics and recap;

  • References to relevant C++ Core Guidelines about error handling;

  • Quizzes with questions to check your knowledge.


What is expected from you?

Please note that this course is not for complete beginners. At least basic C++ skills are required. And you should be able to read and understand C++ code examples of low to medium complexity and size that we cover in lectures.


So, does that sound like this course is for you? If yes, without further to do, enroll and I will see you in the course.


The images in visual examples are from website pixabay and the audio in videos is from website bensound.

Who this course is for:

  • Beginner - intermediate C++ developers
  • Students (either self-taught or at university) with at least basic knowledge of C++
  • Not for complete beginners