Added try-catch to convertToIndex