EXIST HANDLER cannot be part of the procedural code logic. It must be the last item DECLAREd within a BEGIN and END block before any procedural logic code starts.