fix bug catching exception at wrong level