How do I throw/catch exceptions?

This post is a repost of [url]Exception try catch howto which has hasn’t gotten much attention. Maybe this one will.

When I run this…

/* test_exception.cpp */
#ifdef __CINT__
int test_exception( void ){
        cout << endl << "throwing exception...";
        throw exception();
    }catch( exception const&e ){
        cout << "caught!" << endl << e ;
    return 0;

…I get this…

rubix@machine:~$ root -q -b -l test_exception.cpp
root [0] 
Processing test_exception.cpp...
Warning in <TClass::TClass>: no dictionary for class exception is available

throwing exception...(int)-471556992

Anyone know what I’m doing wrong? How should exception throwing/catching be done to play nice with CINT?

  1. The strange warning “no dictionary for class exception is available” is ROOT version specific (I also get it with 5.28, but not with 5.30, so it’s a “bug” in some versions of ROOT) - it comes from the line "#include ", but everything should still work fine, I assume.
  2. Change the line:
    out << “caught!” << endl << e ;
    out << " caught… " << e.what() << endl;


CINT exception handling is somewhat deficient. We recommend to compile (via ACLiC) code that need to rely on exception handling.