Question

counting exceptions

  • 30 January 2014
  • 3 replies
  • 0 views

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

Userlevel 2
Badge +17
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
Userlevel 4
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