add _maybe_throw method for throwing exceptions in the main thread