Disturbance_module.cc
Go to the documentation of this file.
1 /**
2  * @file larexamples/DebuggingExamples/CatchException/Disturbance_module.cc
3  * @brief A module throwing a standard library exception.
4  * @author Gianluca Petrillo (petrillo@fnal.gov)
5  * @date March 21, 2018
6  * @ingroup CatchException
7  */
8 
9 
10 // framework libraries
14 #include "fhiclcpp/types/Atom.h"
15 
16 
17 namespace lar {
18  namespace example {
19 
20  /**
21  * @brief A silly module.
22  *
23  * This module throws and catches a lot of `art::Exception` exceptions.
24  * Kids, don't do this at home!
25  *
26  *
27  * Configuration
28  * ==============
29  *
30  * * *NArtExceptions* (integer, mandatory): number of exceptions to throw
31  *
32  */
33  class Disturbance: public art::EDProducer {
34  public:
35 
36  struct Config {
37 
39  fhicl::Name("NArtExceptions"),
40  fhicl::Comment("number of exceptions to throw")
41  };
42 
43  }; // struct Config
44 
46 
47  /// Constructor.
49 
50  /// Executes the iterations.
51  virtual void produce(art::Event&) override;
52 
53 
54  private:
55 
56  unsigned int fNArtExceptions;
57 
58  /// Throws a `std::out_of_range` exception.
59  static void throwArtException();
60 
61  }; // class Disturbance
62 
63 
64  } // namespace example
65 } // namespace lar
66 
67 //------------------------------------------------------------------------------
69  : EDProducer{config}
70  , fNArtExceptions(config().NArtExceptions())
71  {}
72 
73 
74 //------------------------------------------------------------------------------
76 
77  //
78  // art::Exception
79  //
80  for (unsigned int i = 0; i < fNArtExceptions; ++i) {
81  try {
83  }
84  catch (art::Exception const&) {}
85  } // for
86 
87 } // lar::example::Disturbance::produce()
88 
89 
90 //------------------------------------------------------------------------------
92 
94  << "I want to annoy you.\n";
95 
96 } // lar::example::Disturbance::throwArtException()
97 
98 
99 //------------------------------------------------------------------------------
101 
102 
103 //------------------------------------------------------------------------------
EDProducer(fhicl::ParameterSet const &pset)
Definition: EDProducer.h:20
ChannelGroupService::Name Name
fhicl::Atom< unsigned int > NArtExceptions
virtual void produce(art::Event &) override
Executes the iterations.
static void throwArtException()
Throws a std::out_of_range exception.
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:67
static Config * config
Definition: config.cpp:1054
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
#define Comment
LArSoft-specific namespace.
Disturbance(Parameters const &config)
Constructor.