Determining exception type after the exception is caught?

前端 未结 9 1243
梦毁少年i
梦毁少年i 2020-12-01 01:20

Is there a way to determine the exception type even know you caught the exception with a catch all?

Example:

try
{
   SomeBigFunction();
}
catch(...)         


        
9条回答
  •  南方客
    南方客 (楼主)
    2020-12-01 01:55

    If you're using Visual C++ (managed), you can use the GetType() method to get the type of exception and handle it from there.

    E.g.

    try
        {
            // Run the application
            Application::Run(mainForm);
        }
        catch (Exception^ e)
        {
            String^ exception_type = e->GetType()->ToString();
            throw;
        }
    

    The string will contain something like "System.ArgumentOutOfRangeException".

提交回复
热议问题