Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 250175
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T21:29:21+00:00 2026-05-11T21:29:21+00:00

If I do the following, how does the runtime determine the type of the

  • 0

If I do the following, how does the runtime determine the type of the thrown exception? Does it use RTTI for that?

try
{
  dostuff(); // throws something
}
catch(int e)
{
  // ..
}
catch (const char * e)
{
  // ..
}
catch (const myexceptiontype * e)
{
  // ..
}
catch (myexceptiontype e) // is this the same as the previous handler?
{
  // ..
}

See also:

How is the C++ exception handling runtime implemented?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T21:29:21+00:00Added an answer on May 11, 2026 at 9:29 pm

    Unlike the concerns asked in that other questions, the answer to this question can be answered entirely by means of the Standard. Here are the rules

    A handler is a match for an exception object of type E if

    • The handler is of type cv T or cv T& and E and T are the same type (ignoring the top-level cv-qualifiers), or
    • the handler is of type cv T or cv T& and T is an unambiguous public base class of E, or
    • the handler is of type cv1 T* cv2 and E is a pointer type that can be converted to the type of the handler by either or both of
      • a standard pointer conversion (4.10) not involving conversions to pointers to private or protected or ambiguous classes
      • a qualification conversion

    [Note: a throw-expression which is an integral constant expression of integer type that evaluates to zero
    does not match a handler of pointer type; that is, the null pointer constant conversions (4.10, 4.11) do not
    apply. ]

    As i’m not quite sure about your level of understanding of the Standard, i will leave this unexplained, and answer as you ask.

    With regard to whether it uses RTTI or not – well, the type of the exception object being thrown is the static type of the expression you hand over to the throw statement (some time ago, i had fun figuring this out in GCC). So it does not need to do runtime type identification. So it happens, with g++, that at the side where the throw appears, it hands over a std::type_info object representing the type of the exception object, the object itself and a destructor function.

    It’s then thrown and frames are searched for a matching handler. Using information found in big tables (located in a section called .eh_frame), and using the return address, it looks what function is responsible for the next handling. The function will have a personality routine installed that figures out whether it can handle the exception or not. This whole procedure is described (and in more detail, of course) in the Itanium C++ ABI (implemented by G++) linked by @PaV.

    So, to conclude

    myexceptiontype e
    

    and

    const myexceptiontype *e
    

    Do not handle the same type, of course.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The following code does not catch an exception, when I try to divide by
Why does the following code get the runtime error: Members of the Triggers collection
Does the following exception make sense to you? I'm struggling to identify the cause.
I have the following jQuery that does find the ASP.NET server control (tested by
I'm creating a service that runs in the background. It does the following: Gathers
I'm trying to create a function in Groovy that does the following: Accepts 2
I have created an application that does the following: Make some calculations, write calculated
There's a common error that gets thrown by the Visual C Runtime: This application
Quiz: what does the following program print? using System; using System.Runtime.InteropServices; namespace ConsoleApplication2 {
Does C++ offer a way to 'show' something visual if an unhandled exception occurs?

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.