OOP344: Exception Handling

In this course (OOP344), C++ will cover Exception Handling later on in this course. According to Evan Weaver’s notes, the Exception Handling occurs when the program has errors, and the logic does not terminate the program. Instead, there are catch block intercepts the error and displays desirable messages to the users.

Exception handlers are useful for things like reading and writing to disc. If file is not available, instead of terminating the program we can create meaningful error messages. Also, if file is readonly, we can redirect the error message to be displayed.

Exception handling involves three C++ keywords: try, throw, and catch ().

I have played with the following code like:

#include <iostream>
using namespace std;

int main () {
    throw 20;
  catch (int e)
    cout << "An exception occurred. Exception Number " << e << endl;
  return 0;

I have understood the logic flow in exception handling process. However the mistery to me, is understanding which catch blocks catches a specific throw.

I hope to learn it in the next classes.

Posted in Uncategorized | Leave a comment