[Anjali] Changed the logic to throw the 1st incorrect error. Refactored the code for bubbling up exceptions.