Perhaps you could actually tell us where in this extensive code the exception is thrown. Regardless, if you want to perform an action only if a condition is true then you use an If statement for that.