File indexing completed on 2025-01-18 10:17:42
0001
0002
0003
0004
0005 #ifndef JANA2_USEREXCEPTIONTESTS_H
0006 #define JANA2_USEREXCEPTIONTESTS_H
0007
0008
0009 #include <JANA/JEventSource.h>
0010 #include <JANA/JEventProcessor.h>
0011
0012
0013
0014 struct FlakySource : public JEventSource {
0015
0016 bool open_excepts, getevent_excepts;
0017 int event_count = 0;
0018
0019 FlakySource(bool open_excepts, bool getevent_excepts)
0020 : open_excepts(open_excepts), getevent_excepts(getevent_excepts) {
0021 SetCallbackStyle(CallbackStyle::ExpertMode);
0022 }
0023
0024 void Open() override {
0025 if (open_excepts) {
0026 throw JException("Unable to open source!");
0027 }
0028 }
0029
0030 Result Emit(JEvent&) override {
0031
0032 if (++event_count > 10) {
0033 return Result::FailureFinished;
0034 }
0035
0036 if (getevent_excepts) {
0037 throw JException("Unable to getEvent!");
0038 }
0039 return Result::Success;
0040 }
0041 };
0042
0043
0044
0045 struct FlakyProcessor : public JEventProcessor {
0046
0047 bool init_excepts, process_excepts, finish_excepts;
0048
0049 FlakyProcessor(bool init_excepts, bool process_excepts, bool finish_excepts)
0050 : init_excepts(init_excepts)
0051 , process_excepts(process_excepts)
0052 , finish_excepts(finish_excepts)
0053 {
0054 SetCallbackStyle(CallbackStyle::ExpertMode);
0055 };
0056
0057 void Init() override {
0058 if (init_excepts) {
0059 throw JException("Unable to init!");
0060 }
0061 };
0062
0063 void Process(const JEvent&) override {
0064 if (process_excepts) {
0065 throw JException("Unable to process!");
0066 }
0067 }
0068
0069 void Finish() override {
0070 if (finish_excepts) {
0071 throw JException("Unable to finish!");
0072 }
0073 }
0074 };
0075
0076
0077 #endif