Skip to main content
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
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
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
Thanks guys.  The class instance variable works bette

 

 

'Kemi

Reply