uC++ EHM

Catch-Any

catch-any is a mechanism to match any exception propagating through a guarded block — the final backstop.

Why do we need a catch-any beyond a base-class handler?

With a full exception hierarchy rooted at one type (Java’s Exception, for instance), catching the root is catch-any. But C++ has no forced root, so it needs special syntax catch(...) to mean “anything”. uC++ inherits that pattern and adds _CatchResume(...) for the resumption side.

Forms in uC++

try {
    ...
} _CatchResume( ... ) {    // resumption catch-any — MUST be last _CatchResume
    ...       // e.g., logging
    _Resume;  // re-resume for fixup
} catch( ... ) {           // termination catch-any — MUST be last catch
    ...       // e.g., cleanup
    _Throw;   // rethrow for recovery
}

When each is used

  • Termination catch-any — a general cleanup when a non-specific exception occurs. Typically logs, then rethrows so somebody upstream can decide what to do.
  • Resumption catch-any — lets a guarded block gather information about control flow (e.g., logging every resumption that passes through) without consuming the exception. It then _Resumes to continue propagation.

Java finally vs. catch-any

try { ... } catch( E ) { ... } finally { ... /* always executed */ }

finally provides both catch-any-like cleanup and handles the non-exceptional case — difficult to mimic in C++/uC++ even with RAII because finally can see local variables the destructor cannot.