Skip to content
ConsoleMonster
Class

ExceptionInfo

ConsoleMonster.Widgets

Namespace
ConsoleMonster.Widgets
Assembly
ConsoleMonster
Modifiers
sealed

What ExceptionView shows of an error: the type, the message, the stack frames, the inner error and, for PowerShell errors, the category, the error id, the script stack and the position message. Built from a .NET exception with ExceptionInfo.FromException, or filled in by a host (the PowerShell module maps ErrorRecords).

Inheritance

  • object
  • ExceptionInfo

Usage

Explore 3 API references to this type

This type appears in these public API surfaces even when no hand-authored example is attached directly to the page.

Returned or exposed by 2

Accepted by parameters 1

Constructors

public ExceptionInfo(string type, string message) #

Creates an error description.

Parameters

type string required
The type name (short or full).
message string required
The message.

Methods

public static ExceptionInfo FromException(Exception exception, int depth = 8) #

Describes a .NET exception and its inner exceptions (aggregate exceptions follow their first inner).

Parameters

exception System.Exception required
The exception.
depth int = 8 optional
How many inner exceptions to follow (default 8).

Returns

ExceptionInfo The description.
public static bool IsFrameworkMethod(string method) #

Whether a method belongs to the framework (System, Microsoft, the PowerShell engine) rather than the app.

Parameters

method string required
The method as the stack trace names it.

Returns

bool True for framework frames.
public static List<ExceptionFrame> ParseScriptStackTrace(string? scriptStackTrace) #

Parses a PowerShell script stack trace ("at Get-Thing, C:\x.ps1: line 12", "at <ScriptBlock>, <No file>: line 1").

Parameters

scriptStackTrace string? required
The script stack trace text, or null.

Returns

List<ExceptionFrame> The frames.
public static List<ExceptionFrame> ParseStackTrace(string? stackTrace) #

Parses a .NET stack trace ("at Type.Method(args) in C:\file.cs:line 42", one frame per line).

Parameters

stackTrace string? required
The stack trace text, or null.

Returns

List<ExceptionFrame> The frames.

Properties

public string Type { get; } #

The type name.

public string Message { get; } #

The message.

public string? CommandName { get; set; } #

The failing command's name, or null for an error without a command invocation.

public List<ExceptionFrame> Frames { get; } #

The .NET stack frames, innermost call first, as the runtime lists them.

public List<ExceptionFrame> ScriptFrames { get; } #

The PowerShell script stack (commands and script lines), or empty.

public string? PositionMessage { get; set; } #

The PowerShell position message ("At C:\x.ps1:12 char:5" with the line and the marker), or null.

public string? SourceLine { get; set; } #

The original invocation line, without the host's position-message prefixes.

public string? ScriptPath { get; set; } #

The invocation's script path, when known.

public int LineNumber { get; set; } #

The one-based source line number, or zero when unavailable.

public int ColumnNumber { get; set; } #

The one-based UTF-16 offset of the failing expression, or zero when unavailable.

public int ErrorLength { get; set; } #

The failing expression's length in UTF-16 characters (default one).

public string? Category { get; set; } #

The PowerShell category and reason, for example "ObjectNotFound (C:\missing:String)", or null.

public string? Target { get; set; } #

The PowerShell error target, when supplied by the producer.

public string? ErrorId { get; set; } #

The PowerShell error id, for example "PathNotFound,Microsoft.PowerShell.Commands.GetItemCommand", or null.

public ExceptionInfo? Inner { get; set; } #

The error that caused this one, or null.