Readme: update errors example

This commit is contained in:
Kare Morstol
2020-07-01 23:21:29 +02:00
committed by GitHub
parent fb7fc2c9ad
commit 4da45e4e6f
+4 -4
View File
@@ -392,12 +392,12 @@ runAsync("cmd1", "arg1").stdout.runAsync("cmd2").stdout.write(to: &file)
If the command provided to `runAsync` could not be launched for any reason the program will print the error to standard error and exit, as is usual in scripts. The `runAsync("cmd").finish()` method throws an error if the exit code of the command is anything but 0:
```swift
let command = runAsync("cmd", "-n", 245)
let someCommand = runAsync("cmd", "-n", 245)
// ...
do {
try command.finish()
} catch CommandError.returnedErrorCode(let error) {
// use error.command or error.errorcode
try someCommand.finish()
} catch let CommandError.returnedErrorCode(command, errorcode) {
print("Command '\(command)' finished with exit code \(errorcode).")
}
```