Throw an exception instead of returning -1