---
title: "Re-throwing an exception"
subject: "Object Oriented Programming"
chapter: 10
key: "semester_3/object_oriented_programming:exception-rethrow"
source: https://www.bctengineer.com/q/semester_3/object_oriented_programming/exception-rethrow
site: BCT Engineering
---

# Re-throwing an exception

Object Oriented Programming · Chapter 10: Exception Handling

- Asked in: 2074 Asoj, 5 marks
- Video: [ReThrow Exception In C++](https://www.youtube.com/watch?v=VYoJ4ODzFXE) — CppNuts
- Answer checked by Claude Opus 5.5 (high effort) on 2026-10-14
- Page: https://www.bctengineer.com/q/semester_3/object_oriented_programming/exception-rethrow
- Whole chapter: https://www.bctengineer.com/md/semester_3/object_oriented_programming/chapter-10

## Question

How is the exception re-thrown during exception handling?

## Short answer

Inside a catch block, throw; (without operand) re-throws the same exception to an outer handler. It allows partial handling (e.g., logging) and passes the exception up. Only valid within a catch handler.

## Answer

**Re-throwing** means a handler catches an exception, does part of the work (such as logging or cleanup) and then passes the same exception to an outer handler. It is done with `throw;` (the `throw` keyword **without any operand**) inside a catch block. The original exception object is thrown again to the next enclosing try-catch.

Rules:
- `throw;` is valid only inside a catch handler (or a function called from it); otherwise `terminate()` is called.
- The exception must be caught by an outer try-catch (the caller), otherwise the program terminates.

#### Example

```cpp
#include <iostream>
using namespace std;

void divide(int a, int b) {
    try {
        if (b == 0)
            throw b;                       // throw int
        cout << a / b << endl;
    }
    catch (int) {
        cout << "Inner handler: caught, re-throwing\n";
        throw;                             // re-throw same exception
    }
}

int main() {
    try {
        divide(10, 0);
    }
    catch (int) {
        cout << "Outer handler: division by zero handled\n";
    }
    return 0;
}
```

**Output**

```text
Inner handler: caught, re-throwing
Outer handler: division by zero handled
```

It lets the inner function do local cleanup while the decision about the final action stays with the caller.

## Check yourself

The answer's key points as multiple-choice questions, with the correct option and why.

1. How is an exception re-thrown?
   A. throw again with a new try
   B. retry;
   C. catch;
   D. throw; with no operand inside a catch block
   Answer: D. throw; with no operand re-throws the same exception to the outer handler. (Key point: Rethrow syntax)

2. Why would a handler re-throw?
   A. To do local work such as cleanup and let the caller decide the final action
   B. To ignore the exception
   C. To skip the outer try
   D. To stop the program
   Answer: A. The inner handler does its part and passes the exception on. (Key point: Why rethrow)

3. What happens if a re-thrown exception is not caught by an outer handler?
   A. It is ignored
   B. The program terminates
   C. The compiler reports an error
   D. It is caught by the same handler again
   Answer: B. An uncaught rethrown exception ends the program. (Key point: Rule if uncaught)

## Related in Object Oriented Programming

- [Exception handling constructs](https://www.bctengineer.com/question.md?key=semester_3%2Fobject_oriented_programming%3Aexception-handling-constructs) — Object Oriented Programming, chapter 10, asked 4×
- [Exception handling over conventional error handling](https://www.bctengineer.com/question.md?key=semester_3%2Fobject_oriented_programming%3Aexception-advantages) — Object Oriented Programming, chapter 10

## Related in other subjects

- [Exception handling: OO vs conventional](https://www.bctengineer.com/question.md?key=semester_6%2Fobject_oriented_analysis_and_design%3Aexception-error-handling-oo-vs-conventional) — Object Oriented Analysis and Design, chapter 4
