https://kotlinlang.org logo
#getting-started
Title
# getting-started
p

Patrício

02/24/2024, 12:38 PM
Hi there If this line:
val birthDate = LocalDate.parse("2000-3-10")
throws the following exception:
Exception in thread "main" kotlinx.datetime.DateTimeFormatException: java.time.format.DateTimeParseException: Text '2000-3-10' could not be parsed at index 5
, why I can't do that:
Copy code
package org.example

import kotlinx.datetime.LocalDate
import kotlinx.datetime.DateTimeFormatException

fun main() {
    try {
        val birthDate = LocalDate.parse("2000-3-10")
    } catch (e: DateTimeFormatException) {
        // ...
    }
}
? It raises the following error:
Cannot access 'DateTimeFormatException': it is internal in 'kotlinx.datetime'
What am I missing? Thank you
Also, importing this
import java.time.format.DateTimeParseException
instead, does not work
a

Adrijan Rogan

02/24/2024, 1:19 PM
You can catch
IllegalArgumentException
instead. https://github.com/Kotlin/kotlinx-datetime/issues/153
👍 1
2 Views