/**
 * Given a list of artists, modify the element at the specified index with the new artist name.
 *
 * @param artistList A list of artist names.
 * @param index The index at which the artist name needs to be modified.
 * @param newElement The new artist name to be inserted at the specified index.
 * @return The modified list of artists.
 * @throws IndexOutOfBoundsException If the index is out of range of the list.
 * @throws IllegalArgumentException If the new artist name is empty or contains only whitespace.
 */
fun modifyList(artistList: MutableList<String>, index: Int, newElement: String): List<String> {

    try {
        if (artistList.isEmpty()) {
            throw IndexOutOfBoundsException("The list is empty. Cannot modify elements.")
        }

        if (index < 0 || index >= artistList.size) {
            throw IndexOutOfBoundsException("The index is out of range of the list.")
        }

        if (newElement.trim().isEmpty()) {
            throw IllegalArgumentException("The new artist name is empty or contains only whitespace.")
        }

        artistList[index] = newElement
    } catch (e: IndexOutOfBoundsException) {
        println("Error: $e")
        return artistList
    } catch (e: IllegalArgumentException) {
        println("Error: $e")
    }

    return artistList
}
/**
 * Given a list of artists, modify the element at the specified index with the new artist name.
 *
 * @param artistList A list of artist names.
 * @param index The index at which the artist name needs to be modified.
 * @param newElement The new artist name to be inserted at the specified index.
 * @return The modified list of artists.
 * @throws IndexOutOfBoundsException If the index is out of range of the list.
 * @throws IllegalArgumentException If the new artist name is empty or contains only whitespace.
 */
fun modifyList(artistList: MutableList<String>, index: Int, newElement: String): List<String> {
/**
 * Given a list of artists, modify the element at the specified index with the new artist name.
 *
 * @param artistList A list of artist names.
 * @param index The index at which the artist name needs to be modified.
 * @param newElement The new artist name to be inserted at the specified index.
 * @return The modified list of artists.
 * @throws IndexOutOfBoundsException If the index is out of range of the list.
 * @throws IllegalArgumentException If the new artist name is empty or contains only whitespace.
 */
fun modifyList(artistList: MutableList<String>, index: Int, newElement: String): List<String> {

    try {
        if (artistList.isEmpty()) {
            throw IndexOutOfBoundsException("The list is empty. Cannot modify elements.")
        }

        if (index < 0 || index >= artistList.size) {
            throw IndexOutOfBoundsException("The index is out of range of the list.")
        }

        if (newElement.trim().isEmpty()) {
            throw IllegalArgumentException("The new artist name is empty or contains only whitespace.")
        }

        artistList[index] = newElement
    } catch (e: IndexOutOfBoundsException) {
        println("Error: $e")
        return artistList
    } catch (e: IllegalArgumentException) {
        println("Error: $e")
    }

    return artistList
}