Python Custom Exception Handling
Question: After much googli searching to figure out whats going on, here it is:

I have a custom validation exception which takes a request and response

    
    
    class ValidationException(Exception):
        message = "Caught Validation Exception"
    
        def __init__(self, request, response):
            self.details = {
                "request": request,
                "response": response
            }
            super(ValidationException, self).__init__(self.message, self.details)
    

I have an exception handler which will raise an instance of it on some
condition:

    
    
    class handler:
        if something:
            raise ValidationException(request, response)
    

The handler is called in the event we encounter an issue in a post

    
    
    class Poster:
        def post(data):
            if self.last_response.status_code not in self.valid_post_codes:
                self.exception_handler.handleException(self.last_request, self.last_response)
    

The problem is, I'm raising the ValidationException, getting it in my
traceback, but, it doesn't seem to get caught where I want it.

    
    
    def testThis(self):
        try:
            self.poster.post(json.dumps({}))
        except ValidationException:
            print "got validation"
        except Exception:
            print "got exception"
    

Result: "got exception"

traceback

    
    
    lib/service/pas/api/order.py line 24 in postOrder
      return self.post()
    lib/service/base.py line 42 in post
      self.exception_handler.handleException(self.last_request, self.last_response)
    lib/service/exception/handler.py line 14 in handleException
      raise ValidationException(request, response)
    ValidationException:
    

For what its worth:

    
    
    assertRaises(ValidationException, self.poster.post, json.dumps({}))
    

only catches Exception as well. Any ideas? :\ Any help is greatly appreciated!
Thanks in advance


Answer: Well well well... So..

My IDE prefixed my import with "lib" which imported
Exceptions.ValidationException.

When I throw my.own.ValidationException elsewhere, it wasn't being caught as
it wasn't of the same type. Just so turned out there happened to be another
ValidationException I didn't know about...

Thats amazing, NOT!

