helper function for exception throwing