[Swift-user] Swift error handling

Michael Wilde wilde at mcs.anl.gov
Mon Dec 17 18:25:26 CST 2012


Hi Thomas,

> I noticed that when a bash script that is being called from a Swift
> script fails (returns error 1), the Swift script will fail and give a
> File Not Found error.

Right. Its complaining that the bash script did not produce one or more files that it was expected to produce based on the app() declaration.

> Is there an error handling mechanism in Swift
> that lets us know if the bash script is failing and lets us handle it
> in the Swift script?

No, not at the present time.

The best way to do this is to check for failures in the bash script and return some representation of that failure in a file, which the Swift script can then process via readData().

for example:

(out, error) = myBashScript(args);
errorString = readData(error);
if (errorString == "SomeErrorCondition") {
  # handle error here...
}

- Mike

> Cheers,
> Thomas

-- 
Michael Wilde
Computation Institute, University of Chicago
Mathematics and Computer Science Division
Argonne National Laboratory




More information about the Swift-user mailing list