Hi guys :), long time ^^

I have a question, I hope to get the answer :)

"what is the name of all c++ exception handlers?"


thanks in advance :)

Dani AI

Generated

As observed, in standard C++ an "exception handler" is what you write to receive a thrown exception — in practice that means the catch clause. Textbook wording can differ, though, so the exercise in your book might expect either the single handler keyword or a short taxonomy of handler forms. was also right to suggest reading the chapter: authors often define terms used in exercises.

Common handler forms you will see in real code are: catching by value, by pointer, and by reference, plus the catch-all form. For polymorphic or library exceptions prefer catching by const reference to avoid object slicing and unnecessary copies. When working with standard exceptions, const std::exception& gives access to what(). Reserve catch(...) for last-resort logging or translation; it should usually rethrow or convert the error rather than silently swallow it.

Minimal pattern to keep in mind:

try {
    // code that may throw
} catch (const std::exception& e) {
    // handle known exceptions
} catch (...) {
    // fallback: log/translate/rethrow
}

There are also related library and runtime pieces worth knowing: std::terminate is invoked when an exception is not handled or an exception is thrown during stack unwinding; std::exception_ptr, std::current_exception, and std::rethrow_exception let you capture and rethrow exceptions (useful across threads). For a concise, authoritative reference see the C++ language exception page and the std::exception overview on cppreference: C++ exception handling and std::exception.

Recommended Answers

All 6 Replies

I think you have your terminology mixed up. Can you give an example of one or two "exception handlers" that you're familiar with so we know what the hell you're talking about?

I think you have your terminology mixed up. Can you give an example of one or two "exception handlers" that you're familiar with so we know what the hell you're talking about?

Well, to be honest I was looking at my book and that question attract me, and now I'm looking for an answer

The question is: "what is the name of all c++ exception handlers?"

the book is called (Concepts of Programming Languages)..

:icon_rolleyes: Perhaps you should read the chapter which asks that question. Most likely the author defines "exception handler" so that it makes more sense.

You see, the standard terminology is that an exception handler is one of the catch clauses in a try..catch. Because the construction of a catch clause is effectively infinite, there's no way to "name" all of them. Unless the answer to the question is "Oh, there's only one and it's called catch", your book is using a non-standard definition of "exception handler".

:icon_rolleyes: Perhaps you should read the chapter which asks that question. Most likely the author defines "exception handler" so that it makes more sense.

You see, the standard terminology is that an exception handler is one of the catch clauses in a try..catch. Because the construction of a catch clause is effectively infinite, there's no way to "name" all of them. Unless the answer to the question is "Oh, there's only one and it's called catch", your book is using a non-standard definition of "exception handler".

yeah, may be as you said (catch) or may be as I though (exception mechanism), I'll keep both answers, and I'm gonna read the chapter to confirm the correct answer :)

thanks a lot for being on touch :)

I would have thought it wise to have read the chapter before doing the extercises at the end of the chapter :)

I would have thought it wise to have read the chapter before doing the extercises at the end of the chapter :)

yeah I guess that's the best, but I said "how about taking a shortcut and ask the guys here! hehehehe :D"

thanks ^^

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.