Circular Buffer exercise

Hi, I’m trying the circular buffer exercise, I’m only on the first test, so I’ve only done the first exception and the first test but I’m getting this error.

In my ide I control the exception in main with try catch, and it works correctly but I don’t know how to do it if I only have the class. As you can see I’m very new, I’m just starting with Kotlin. If someone can guide me on where to look I’d appreciate it.

[ERROR] src/test/kotlin/CircularBufferTest.kt:[51,25] Type argument is not within its bounds: should be subtype of 'Throwable'

My code:

import kotlin.collections.ArrayDeque

// TODO: implement proper exceptions to complete the task
class EmptyBufferException(message: String = "Is Empty") :Exception(message)

class BufferFullException()

class CircularBuffer<T>(private val capacity: Int) {
    // TODO: implement proper constructor to complete the task
        val deque = ArrayDeque<T>()

    fun read() : T {
        if (deque.isEmpty())
            throw EmptyBufferException("EmptyBufferException")
        return deque.first()
    }

    fun write(value: T) {
        TODO("Implement this function to complete the task")

    }

    fun overwrite(value: T) {
        TODO("Implement this function to complete the task")
    }

    fun clear() {
        TODO("Implement this function to complete the task")
    }
}

I edited your post to add codeblocks :slight_smile: It’s much easier to read now.

Thanks, I’ll use it next time.