Aggregating Exceptions

When more than one Try/Catch is needed

Exception handling may become a bit more complex when a process must handle different contexts - when you need to aggregate Exceptions. A very common example is a CSV import process, that runs periodically and reads one or more files from sFTP to send each line to a backend-service.

An import process with different contexts

A Try/Catch block works in the context of the Documents which flow through the Try block.

Initially, when the process starts, there is no document and the Try/Catch works in the process context (orange). Then you read the files from sFTP and a Try/Catch block works in the context of the files (green). Then you split the CSVs into rows and another Try/Catch block works in the context of the rows (blue).

Three Try/Catch block - one for each context

It is important to understand that you catch (and collect) the Exceptions per context to forward (re-throw) an aggregated exception to the "previous" context. Finally, on the process Try/Catch you have got the aggregation of all Exceptions. And this is normally the place where you implement the aggregated Exception handler to send one e-mail.

Last updated