I am trying to make my own exception classes this ...
# getting-started
e
I am trying to make my own exception classes this way:
Copy code
// 4xx without errorCode
class UnknownClientRequestException(
    message: String,
    error: ClientRequestException
): RuntimeException(
    message = "$message (server code: ${error.response.status.value}, message: ${error.response.status.description})",
    cause = error
)
But I am getting compile time errors:
Cannot find a parameter with this name: message
,
Cannot find a parameter with this name: cause
What am I doing wrong?
a
RuntimeException is a Java class, and you can't use named arguments with Java classes https://discuss.kotlinlang.org/t/what-is-the-reason-for-not-allowing-named-arguments-for-java-interop/4571
plus1 2
e
If RuntimeException is declared in stdlib as an
expect class
, how will be translated on other platforms? I see that Ktor also uses it as a base class for it’s own exceptions. If it is multiplatform class it is weird that I can’t use it in normal kotlin way.
a
on JVM it's an
actual typealias
, and in other targets it's an
actual class
(e.g. on JS) https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-runtime-exception/
e
When I use it in the common multiplatform module why I can’t use the named arguments if it is the native Kotlin expect class?