Skip to content

Commit 08e3350

Browse files
Duncan McGregordmcg
authored andcommitted
exceptions-to-values.9 : process IOException
1 parent e2beb0b commit 08e3350

File tree

1 file changed

+22
-20
lines changed

1 file changed

+22
-20
lines changed

src/main/java/travelator/marketing/HighValueCustomersMain.kt

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,32 @@
11
package travelator.marketing
22

3-
import java.io.Closeable
4-
import java.io.OutputStreamWriter
5-
import java.io.Reader
6-
import java.io.Writer
3+
import java.io.*
74
import kotlin.system.exitProcess
85

96
fun main() {
10-
val statusCode = using(
11-
System.`in`.reader(),
12-
System.out.writer(),
13-
System.err.writer()
14-
) { reader, writer, error ->
15-
val errorLines = mutableListOf<ParseFailure>()
16-
val reportLines = reader
17-
.asLineSequence()
18-
.toHighValueCustomerReport {
19-
errorLines += it
7+
val statusCode = try {
8+
using(
9+
System.`in`.reader(),
10+
System.out.writer(),
11+
System.err.writer()
12+
) { reader, writer, error ->
13+
val errorLines = mutableListOf<ParseFailure>()
14+
val reportLines = reader
15+
.asLineSequence()
16+
.toHighValueCustomerReport {
17+
errorLines += it
18+
}
19+
if (errorLines.isEmpty()) {
20+
reportLines.writeTo(writer)
21+
0
22+
} else {
23+
errorLines.writeTo(error)
24+
-1
2025
}
21-
if (errorLines.isEmpty()) {
22-
reportLines.writeTo(writer)
23-
0
24-
} else {
25-
errorLines.writeTo(error)
26-
-1
2726
}
27+
} catch (x: IOException) {
28+
System.err.println("IO error processing report ${x.message}")
29+
-1
2830
}
2931
exitProcess(statusCode)
3032
}

0 commit comments

Comments
 (0)