I should say I'm running into this while poking ar...
# announcements
g
I should say I'm running into this while poking around at generics with types of exceptions, and I've found something rather odd:
Copy code
private fun <X : Throwable> doesntThrow(call : () -> Any): Boolean {
        return try{ call(); true }
        catch( ex : X ){ false }
    }

    @Test fun `when using type parameter for exception somehow type erasure doesnt screw us`(){

        val resultOfNonThrowing = doesntThrow<IllegalArgumentException> { val x = 5; Unit }
        val resultOfThrowingThing = doesntThrow<IllegalArgumentException> { throw IllegalArgumentException() }
        val resultOfThrowingOtherThing = doesntThrow<IllegalArgumentException> { throw NullPointerException() }

        assertThat(resultOfNonThrowing).isTrue();
        assertThat(resultOfThrowingThing).isFalse();

        assertThat(resultOfThrowingOtherThing).isFalse();  //but it does :(
    }