RAD Studio
ContentsIndex
PreviousUpNext
E2018: Cannot catch 'identifier' -- ambiguous base class 'identifier' (C++)

It is not legal to catch a class that contains more than one copy of a (non-virtual) base class. However, you can catch the exception as a more derived type. For example:

struct awkward : std::runtime_error, std::logic_error {};

 try {
 }
 catch( std::exception & ) { // ambiguous, not caught here
 }
 catch( std::runtime_error & ) { // caught here 
 }

Note that the compiler might warn you that the second catch cannot be triggered because the first clause should catch all matching exceptions. But the ambiguous base case is caught by the second clause.

Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
What do you think about this topic? Send feedback!