Moved emit outside try/catch