C++ exception caught

Hi,

I have a macro that used to run fine in root before and now suddenly it is throwing an error as
’Error: C++ exception caught’ and it terminates.

What does this mean? And how can I avoid it?

  • Sujeewa

Hi again,

Ok, so I saw this post by Philippe (osdir.com/ml/lang.c++.root/2006-02/msg00007.html) and added the line gROOT->ProcessLine(".exception");
to my macro.

Now it fails with an error-
Progress: 20%
terminate called after throwing an instance of 'std::out_of_range’
what(): vector::_M_range_check

What is going on here? Any insight will be much appreciated!

  • Sujeewa

Hi,

[quote]terminate called after throwing an instance of 'std::out_of_range’
what(): vector::_M_range_check[/quote]This means that your code (directly or indirectly) is trying to access an element of an std::vector object that is beyond the number of actual elements in the vector.

Cheers,
Philippe.

It’s because you are trying to access an element in a vector that does not exist. For exemple, you defined vector a with 5 entries and you are trying to read a.at(5). But the index for a vector start from 0, so 5 (in this example) is not valid. Then you get this seg fault. The 5th object is a.at(4), as the first is a.at(0)

Cheers.

S Poss.

Thanks guys!

So in general, is it a good thing to add the line gROOT->ProcessLine(".exception"); ? This will give me more information on why my code actually fails, right?

  • Sujeewa

Hi,

Yes, it does give more information but on the other hand does not allow to continue using the same session (i.e. it forces you to restart ROOT).

Cheers,
Philippe.

I see. Thanks, Philippe!