Simply put - dots in exception message in console are only for display purposes - to not give you wall of text.
If you want to display the FULL exception you can use something like this:
try {
New-Item NONEXISTING:\asd.txt -ErrorAction Stop #This will throw error
Write-Host "If it shows error was not caught"
}
catch {
$_.Exception | Format-List -Force
}
This displays info like below and gives you full info about Exception object :)
ErrorRecord : Cannot find drive. A drive with the name 'NONEXISTING' does not exist.
ItemName : NONEXISTING
SessionStateCategory : Drive
WasThrownFromThrowStatement : False
Message : Cannot find drive. A drive with the name 'NONEXISTING' does not exist.
Data : {}
InnerException :
TargetSite : System.Management.Automation.PSDriveInfo GetDrive(System.String, Boolean)
StackTrace : at System.Management.Automation.SessionStateInternal.GetDrive(String name, Boolean automount)
at System.Management.Automation.SessionStateInternal.GetDrive(String name, Boolean automount)
at System.Management.Automation.LocationGlobber.GetDriveRootRelativePathFromPSPath(String path, CmdletProviderContext context, Boolean escapeCurrentLocation, PSDriveInfo& workingDriveForPath, CmdletProvider& providerInstance)
at System.Management.Automation.LocationGlobber.GetProviderPath(String path, CmdletProviderContext context, Boolean isTrusted, ProviderInfo& provider, PSDriveInfo& drive)
at System.Management.Automation.SessionStateInternal.NewItem(String[] paths, String name, String type, Object content, CmdletProviderContext context)
at Microsoft.PowerShell.Commands.NewItemCommand.ProcessRecord()
HelpLink :
Source : System.Management.Automation
HResult : -2146233087
For full message or stack trace, just go with $_.Exception.Message
or $_.Exception.StackTrace
:
try {
New-Item NONEXISTING:\asd.txt -ErrorAction Stop; #This will throw error
Write-Host "If it shows error was not caught"
}
catch {
Write-Host "MESSAGE`n$($_.Exception.Message)"
Write-Host "STACK TRACE`n$($_.Exception.StackTrace)"
}
and it gives info:
MESSAGE
Cannot find drive. A drive with the name 'NONEXISTING' does not exist.
STACK TRACE
at System.Management.Automation.SessionStateInternal.GetDrive(String name, Boolean automount)
at System.Management.Automation.SessionStateInternal.GetDrive(String name, Boolean automount)
at System.Management.Automation.LocationGlobber.GetDriveRootRelativePathFromPSPath(String path, CmdletProviderContext context, Boolean escapeCurrentLocation, PSDriveInfo& workingDriveForPath, CmdletProvider& providerInstance)
at System.Management.Automation.LocationGlobber.GetProviderPath(String path, CmdletProviderContext context, Boolean isTrusted, ProviderInfo& provider, PSDriveInfo& drive)
at System.Management.Automation.SessionStateInternal.NewItem(String[] paths, String name, String type, Object content, CmdletProviderContext context)
at Microsoft.PowerShell.Commands.NewItemCommand.ProcessRecord()
PS. If you want even more info:
try {
New-Item NONEXISTING:\asd.txt -ErrorAction Stop
Write-Host "If it shows error was not caught"
}
catch {
$_ | Format-List -Force
}
This will display all the info including ScriptStackTrace (at which line the exception occurred):
Exception : System.Management.Automation.DriveNotFoundException: Cannot find drive. A drive with the name 'NONEXISTING' does not exist.
at System.Management.Automation.SessionStateInternal.GetDrive(String name, Boolean automount)
at System.Management.Automation.SessionStateInternal.GetDrive(String name, Boolean automount)
at System.Management.Automation.LocationGlobber.GetDriveRootRelativePathFromPSPath(String path, CmdletProviderContext context, Boolean escapeCurrentLocation, PSDriveInfo& workingDriveForPath, CmdletProvider& providerInstance)
at System.Management.Automation.LocationGlobber.GetProviderPath(String path, CmdletProviderContext context, Boolean isTrusted, ProviderInfo& provider, PSDriveInfo& drive)
at System.Management.Automation.SessionStateInternal.NewItem(String[] paths, String name, String type, Object content, CmdletProviderContext context)
at Microsoft.PowerShell.Commands.NewItemCommand.ProcessRecord()
TargetObject : NONEXISTING
CategoryInfo : ObjectNotFound: (NONEXISTING:String) [New-Item], DriveNotFoundException
FullyQualifiedErrorId : DriveNotFound,Microsoft.PowerShell.Commands.NewItemCommand
ErrorDetails :
InvocationInfo : System.Management.Automation.InvocationInfo
ScriptStackTrace : at <ScriptBlock>, <No file>: line 2
PipelineIterationInfo : {}
PSMessageDetails :