this function is confusing. If you have 'debug' set, it produces an alert and returns. If you don't, it rethrows the exception you pass it. That is incredibly non obvious behaviour.