Add range error handling with a proper exception