refactored exception matching