Skip to content

Commit 18a0e9e

Browse files
ctruchiCLOVIS-AI
authored andcommitted
tp6 step 2 solution
1 parent 7ddb092 commit 18a0e9e

File tree

1 file changed

+6
-2
lines changed
  • tp6/src/main/kotlin/fmt/kotlin/fundamentals

1 file changed

+6
-2
lines changed

tp6/src/main/kotlin/fmt/kotlin/fundamentals/Bottle.kt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,14 @@ data class Bottle(
77
override fun toString() = "Bouteille de $name de $year"
88
}
99

10-
fun String.toBottle(): Bottle {
10+
fun String.toBottle() = try {
1111
val year = takeLast(4)
1212
val substringAfter = substringAfter("Bouteille de ")
1313
val name = substringAfter.substringBefore(" de $year")
1414

15-
return Bottle(name, year.toInt())
15+
Bottle(name, year.toInt())
16+
} catch (e: NumberFormatException) {
17+
null
18+
} finally {
19+
println(this)
1620
}

0 commit comments

Comments
 (0)