JeffersonLab / JANA2

Multi-threaded HENP Event Reconstruction
https://jeffersonlab.github.io/JANA2/
Other
6 stars 9 forks source link

JException doesn't store the underlying exception #277

Closed DraTeots closed 5 months ago

DraTeots commented 6 months ago

As I recall use of JExceptions benefits include better reporting and handling inside JANA2. So it is recommended to use JException and base your own classes on JExpection when working with JANA2. The problem arizes for stubs like this (taken from OmniFactory):

void Process(const std::shared_ptr<const JEvent> &event) override {
        try {
//...
        }
        catch(std::exception &e) {
            throw JException(e.what());
        }
    }

The type of underlying exception sometimes might be the same or more important as e.what() but it gets stripped. I would propose adding something like

 throw JException(e);

With the corresponding reporting

nathanwbrei commented 6 months ago

We hang onto the std::current_exception pointer everywhere else in JANA. I'll modify JOmniFactory to store it there as well. I'm just not sure that it does any good in practice. This is because you'd have to rethrow the stored exception in order to unpack whatever it contains (apart from e.what())

nathanwbrei commented 6 months ago

I personally can't stand how C++ does exceptions at all, compared to literally any other programming language in widespread use. I think Cling actually makes them a lot better, and our JException and JBacktrace is a weak approximation of that. If you have any flashes of inspiration as to how you'd improve JExceptions, feel free to share