Skip to main content
Question

counting exceptions


HI,

 

 

I need help with try and exceptions.  I have a python script in pythoncaller that with try and except, after running the workbench I will like to count the exceptions  and then get an email that there were exceptions.  What is the best way to o about this.  thanks

 

'Kemi

3 replies

takashi
Evangelist
  • January 30, 2014
Hi,

 

 

If you defined a global variable, it can be accessed in Shutdown Pytoh Script.

 

 

-----

 

# Example: PythonCaller script

 

import fmeobjects

 

 

# Define a global variable.

 

g_errorCount = 0

 

 

class FeatureProcessor(object):

 

    def __init__(self):

 

        pass

 

       

 

    def input(self, feature):

 

        try:

 

            # Do something.

 

        except:

 

            # When an error occurred, increase error count.

 

            global g_errorCount

 

            g_errorCount += 1

 

       

 

    def close(self):

 

        pass

 

-----

 

 

Takashi

david_r
Celebrity
  • January 31, 2014
Hi,

 

 

here's an example using a class instance variable rather than a global variable.

 

 

Example:

 

 

---

 

import fmeobjects

 

 

class FeatureProcessor(object):

 

    def __init__(self):

 

        self.exception_count = 0

 

     

 

    def input(self, feature):

 

        try:

 

            # Do something.

 

        except:

 

            # When an error occurrs, increase error count

 

            self.exception_count += 1

 

     

 

    def close(self):

 

        if self.exception_count > 0:

 

            # Send a mail here...

 

---

 

 

David

  • Author
  • January 31, 2014
Thanks guys.  The class instance variable works bette

 

 

'Kemi

Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings