How do I count exceptions when they are raised?
<p>I'm a beginner in programming and I'm having a bit of trouble with the basics of exceptions since I'm working on an exercise right now. </p>

<p>There are two parts to the exercise:</p>

<p>Part A:</p>

<p>I am required to create a class called ExceptionCounter that contains one instance variable, num_exceptions, which starts at 0. ExceptionCounter also has one method, which takes one parameter, a function (in addition to the usual self). check_for_exception calls the function (with no arguments) and increments num_exceptions if any exception is raised.</p>

<p>I have the barebones of the code down except for the part "if any exception is raised". I am passing through a function in which the function body is an object right? So if the function I'm passing has an error, how do I work with that error so that it triggers the increment?</p>

<p>So far this is my code:</p>

<pre><code>class ExceptionCounter(Exception):
    def __init__(self):
        self.num_exceptions = 0

    def check_for_exceptions(self, func):
        try:
            self.func()
        except Exception:
            self.num_exceptions += 1
</code></pre>

<p>But Im getting an 'ExceptionCounter' object has no attribute 'check_for_exception' error. Any ideas on how to fix this?</p>
