You've misunderstood how pipelines work. When a sequence of objects is sent to a pipeline, each individual object is passed through the entire pipeline before the next object is processed. Consider the following functions:
function First() {
process {
Write-Host "First: $_";
$_
}
}
function Second() {
process {
Write-Host "Second: $_";
}
}
The first function outputs "First" and the value of the pipeline object, and then passes the object on. The second merely outputs "Second" and the pipeline object. Now, when you push an array to a pipeline composed of these two functions, what do you expect to see?
The actual result is this:
PS C:\Users\Lauri> ,1,2,3 | first | second
First: 1
Second: 1
First: 2
Second: 2
First: 3
Second: 3
Now, with this information handy, we can deduce that when a function or cmdlet in the pipeline throws an exception to stop processing, the entire pipeline stops. But we can easily verify it too. Let's modify First as follows:
function First() {
process {
throw New-Object System.Management.Automation.PipelineStoppedException
}
}
and then try the same pipeline again:
PS C:\Users\Lauri> ,1,2,3 | first | second
The result is empty, because the moment the first object is passed to "First", it throws an exception, and the entire pipeline is aborted.
In summary, you can't test if the processing was aborted further down the pipeline, because the execution will never get there.
[Edit] One more interesting tidbit: the Begin blocks of all functions are run first, and the End blocks are all run last, so if you throw an exception in the Process block higher up in the pipeline, the Begin block of all the pipeline functions will already have run:
function First() {
begin {
Write-Host "First begin"
}
process {
throw New-Object System.Management.Automation.PipelineStoppedException
}
end {
Write-Host "First end"
}
}
function Second() {
begin {
Write-Host "Second begin"
}
process {
Write-Host "Second: $_"
}
end {
Write-Host "Second end"
}
}
PS C:\Users\Lauri> ,1,2,3 | first | second
First begin
Second begin
[Edit 2]
Another potentially interesting consequence is that if an exception occurs and you want the pipeline to continue after that, you'll need to return something in the catch block that catches it:
function CauseException {
throw New-Object Exception
}
function First() {
process {
try {
CauseException
} catch {
"Error"
}
}
}
function Second() {
process {
Write-Host "Second: $_"
}
}
PS C:\Users\Lauri> ,1,2,3 | first | second
Second: Error
Second: Error
Second: Error