Why are exceptions from JDK type aliased?


#1

Why are type aliases for JDK types like IllegalArgumentException provided by Kotlin? The name is the same, there is no type parameter set – so what is the benefit of these aliases?


#2

There are a few benefits as far as I can tell. One is that kotlin.* is one of the automatically imported packages, therefor giving you access to those exceptions without importing them. The other reason I can think of is multi-platform. Having the type alias allows mapping the exceptions to the JVM version and still allowing the use of them on JS or Native.


#3

I agree with the second reason.

As to the imports - according to the documentation package ‘java.lang’, which contains most of the exception classes, is imported by default


#4

Woops your right. Forgot about that :blush: