Corrected exception test and logic