Added more specific exceptions and check if block end is missing