Throw correct exception in command generator