locked
Why casting an exception is always OK whatever the type of exception?

    Question

  • Hi,

    Does anyone know why a dynamic_cast on an exception is always returning a non null object.

    For example with this code:

    auto error = ref new Platform::InvalidArgumentException();
    auto castedError = dynamic_cast<Platform::InvalidCastException^>(error);
    we might expect that castedError is null, but it's not.

    Thanks

    Note : As a consequence dynamic_cast can't be used to know the type of an exception. the workaround is to use GetType();

    
    


    Tuesday, August 28, 2012 7:09 PM

Answers

  • This is unfortunately a bug in the implementation. Thanks for reporting it. We opened an internal bug to track this - if you want to be kept in the loop with its progress though, please open a Connect bug instead.

    Thank you also for the workaround. This will benefit other customers running into the same issue.

    Marian Luparu
    Visual C++

    Thursday, August 30, 2012 10:52 PM