We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 7ddb092 commit 18a0e9eCopy full SHA for 18a0e9e
tp6/src/main/kotlin/fmt/kotlin/fundamentals/Bottle.kt
@@ -7,10 +7,14 @@ data class Bottle(
7
override fun toString() = "Bouteille de $name de $year"
8
}
9
10
-fun String.toBottle(): Bottle {
+fun String.toBottle() = try {
11
val year = takeLast(4)
12
val substringAfter = substringAfter("Bouteille de ")
13
val name = substringAfter.substringBefore(" de $year")
14
15
- return Bottle(name, year.toInt())
+ Bottle(name, year.toInt())
16
+} catch (e: NumberFormatException) {
17
+ null
18
+} finally {
19
+ println(this)
20
0 commit comments