When I throw a multiline exception message, PowerShell seems to always replace the newline characters with spaces.
E.g.
Line 1: $newline = [System.Environment]::NewLine
Line 2: throw "multiline$newline test"
Yields:
Exception: Test.ps1:2:1
Line |
19 | throw "multiline$newline test"
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| multiline test
For larger multiline exception texts ideally the newline characters should not get replaced.
Any clue how I can ask PowerShell to leave the newline characters?
$PSVersionTable
Name Value
---- -----
PSVersion 7.2.6
PSEdition Core
GitCommitId 7.2.6
OS Microsoft Windows 10.0.22000
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
$ErrorView
ConciseView
If I switch to 'DetailedView' then the newline is not replaced.