In this section of the course, we'll learn about exception handling in c++.
Exception handling is definitely not a beginner topic,
but I wanted to cover the basics so that you can understand exception handling
and be able to move on to more advanced features in exception handling
as you learn more c++.
We'll talk about what an exception is as well as how we can handle exceptions in c++.
Then we'll look at a simple program that has a divide by 0 error,
and we'll add exception handling to it so that we can handle that error.
Once we understand the basics of exception handling,
we'll create a function that throws an exception when something goes wrong within it.
And we'll see how to throw an exception from that function,
and also learn how to catch the exception outside the function and deal with it.
Obviously, when something goes wrong in a program,
the normal flow of control of that program cannot continue
as if nothing has happened.
So it's very important to understand how exception handling
affects the flow of control of your program.
Specifically, we'll learn about stack unwinding.
What it is, and how c++ uses it.
Then we'll create our own exception classes
so that we have complete control over the exception types that we throw and handle.
Finally, we'll look at the standard exception class hierarchy provided by c++,
and we'll look at the types of exceptions that are already defined in c++.
Let me finish off this section overview with a few thoughts.
Writing exception safe code in c++ is extremely difficult,
and it's beyond the scope of this course.
In this section, I want to introduce you to the basic concepts, the syntax
and the behavior of c++ exception handling.
There are several schools of thought when using c++ exception handling.
One is that it should only be used for extremely exceptional conditions,
conditions that would prevent your program from continuing.
Another is that it should never be used.
And then somewhere in the middle is the school of thought that it should
always be used even for not so exceptional situations
and then of course there's all sorts of opinion in between all of these.
I've worked with c++ code where each of these scenarios was used,
and they all have advantages and disadvantages.
It really all comes down to how you define what an exception is.
This section of the course will present a few c++ exception handling
best practices.
But it's very difficult to establish these best practices in c++ because
when and how to use c++ exception handling
is such a hotly debated topic.
Okay. So let's see what exception handling is all about.