Chapter 32: exceptions inside a pipeline, built
A pipeline stage is an ordinary function, so an exception thrown in one travels as any other does. Two things can happen to it: a try around the whole pipeline statement catches it and nothing is collected, or a stage catches inside itself and substitutes a value, and the pipeline carries on. The IDE writes both functions' signatures and the program's shell; you type the throw, the stage's own try and the two pipelines. To play it in the IDE: Help > Lessons > EK9 in Depth…, or ek9 -ide -lesson depth-pipeline-failures.
What you'll build
The lesson builds this program from a file holding only its module line - the finished file, as the book prints it.
#!ek9 defines module book.pipeline.failures defines function parsePrice() -> text as String <- rtn as Integer: Integer(text) if not rtn? throw Exception(`not a price: ${text}`) parsePriceOrZero() -> text as String <- rtn as Integer: 0 try rtn: parsePrice(text) catch -> ex as Exception Stdout().println(`skipped: ${ex.reason()}`) defines program PipelineFailures() stdout <- Stdout() prices <- ["12", "oops", "30", "45"] try total <- cat prices | map with parsePrice | collect as List of Integer stdout.println(`unreachable: ${total}`) catch -> ex as Exception stdout.println(`pipeline stopped: ${ex.reason()}`) recovered <- cat prices | map with parsePriceOrZero | collect as List of Integer stdout.println(`recovered: ${recovered}`)
Step 1: parsePrice — a function
Choose Code > New Construct > Function…
parsePrice is the function's name. Add one parameter, text of type String, set Returns to Integer. Choose Preview.
The preview shows parsePrice about to be written. Choose Apply.
Select the parsePrice() line and, above it, type the blank line the book opens its first function with. Saves when typed.
Select the stub, from <- rtn as Integer? down to its //AI line, and type parsePrice's own return and work, as the book writes them. Saves when typed.
Step 2: parsePriceOrZero — a function
Choose Code > New Construct > Function…
parsePriceOrZero is the function's name. Add one parameter, text of type String, set Returns to Integer. Choose Preview.
The preview shows parsePriceOrZero about to be written. Choose Apply.
Select the stub, from <- rtn as Integer? down to its //AI line, and type parsePriceOrZero's own return and work, as the book writes them. Saves when typed.
Step 3: The program
Choose Code > New Construct > Program…
PipelineFailures is the program's name. Choose Preview.
The preview shows PipelineFailures about to be written. Choose Apply.
Select the PipelineFailures() line and, above it, type the blank line the book opens the program with. Saves when typed.
Select the stub, from ready <- true down to its //AI line, and type PipelineFailures's body exactly as the chapter shows it. Saves when typed.
Step 4: Run it
Choose Run > Run Program…
The project's only program is already chosen. Choose Run.
pipeline stopped: not a price: oops, then skipped: not a price: oops, then recovered: [12, 0, 30, 45]. Choose Close.
The result
PipelineFailures.ek9 now reads exactly as chapter 32 of EK9 in Depth shows it. The first pipeline stopped at oops, which is why unreachable never printed; the second recovered, with 0 standing in for the price that would not parse.
Where this lesson comes from
- Answers -
ek9 -qand the IDE's Answers tab: 136. - For AI assistants - the MCP tool
ek9_new_construct,ek9_add_program.

















