"""Handle handlers."""

import logging

class Handlers(object):
    """Handlers."""

    def __init__(self, *handlers):
        self.handlers = handlers

    def handle(self, event, packet):
        """Handle incoming data."""

        for handler in self.handlers:
            if hasattr(handler, "on_" + event):
                response = ""
                try:
                    response = getattr(handler, "on_" + event)(packet)
                except Exception as e:
                    print("Uh oh!")
                    print(e)
                else:
                    if response is StopIteration:
                        break
                    yield response

class Handler(object):
    """Handler."""
    
    def __init__(self):
        self.logger = logging.getLogger(__name__)

"""Handle handlers."""

import logging


class Handlers(object):
    """Handlers."""

    def __init__(self, *handlers):

        self.logger = logging.getLogger(__name__)

        self.handlers = handlers

    def handle(self, event, packet):
        """Handle incoming data."""

        for handler in self.handlers:
            if hasattr(handler, "on_" + event):
                response = ""
                try:
                    response = getattr(handler, "on_" + event)(packet)
                except Exception as e:
                    self.logger.warning(e)
                else:
                    if response is StopIteration:
                        break
                    yield response

class Handler(object):
    """Handler."""

    def __init__(self):
        self.logger = logging.getLogger(__name__)

Add exception logging to Handlers
Add exception logging to Handlers

  """Handle handlers."""
  
  import logging
+ 
  
  class Handlers(object):
      """Handlers."""
  
      def __init__(self, *handlers):
+ 
+         self.logger = logging.getLogger(__name__)
+ 
          self.handlers = handlers
  
      def handle(self, event, packet):
          """Handle incoming data."""
  
          for handler in self.handlers:
              if hasattr(handler, "on_" + event):
                  response = ""
                  try:
                      response = getattr(handler, "on_" + event)(packet)
                  except Exception as e:
+                     self.logger.warning(e)
-                     print("Uh oh!")
-                     print(e)
                  else:
                      if response is StopIteration:
                          break
                      yield response
  
  class Handler(object):
      """Handler."""
-     
+ 
      def __init__(self):
          self.logger = logging.getLogger(__name__)
  
Add exception logging to Handlers
## Code Before:
"""Handle handlers."""

import logging

class Handlers(object):
    """Handlers."""

    def __init__(self, *handlers):
        self.handlers = handlers

    def handle(self, event, packet):
        """Handle incoming data."""

        for handler in self.handlers:
            if hasattr(handler, "on_" + event):
                response = ""
                try:
                    response = getattr(handler, "on_" + event)(packet)
                except Exception as e:
                    print("Uh oh!")
                    print(e)
                else:
                    if response is StopIteration:
                        break
                    yield response

class Handler(object):
    """Handler."""
    
    def __init__(self):
        self.logger = logging.getLogger(__name__)

## Instruction:
Add exception logging to Handlers
## Code After:
"""Handle handlers."""

import logging


class Handlers(object):
    """Handlers."""

    def __init__(self, *handlers):

        self.logger = logging.getLogger(__name__)

        self.handlers = handlers

    def handle(self, event, packet):
        """Handle incoming data."""

        for handler in self.handlers:
            if hasattr(handler, "on_" + event):
                response = ""
                try:
                    response = getattr(handler, "on_" + event)(packet)
                except Exception as e:
                    self.logger.warning(e)
                else:
                    if response is StopIteration:
                        break
                    yield response

class Handler(object):
    """Handler."""

    def __init__(self):
        self.logger = logging.getLogger(__name__)
