mirror of
				https://github.com/spectreconsole/spectre.console.git
				synced 2025-10-25 15:19:23 +00:00 
			
		
		
		
	
		
			
				
	
	
	
		
			1.6 KiB
		
	
	
	
	
	
	
	
			
		
		
	
	
			1.6 KiB
		
	
	
	
	
	
	
	
Title: Exceptions Order: 3
Exceptions isn't always readable when viewed in the terminal.
You can make exception a bit more readable by using the WriteException method.
AnsiConsole.WriteException(ex);
 
Shortening parts
You can also shorten specific parts of the exception to make it even more readable, and make paths clickable hyperlinks. Whether or not the hyperlinks are clickable is up to the terminal.
AnsiConsole.WriteException(ex, 
    ExceptionFormat.ShortenPaths | ExceptionFormat.ShortenTypes |
    ExceptionFormat.ShortenMethods | ExceptionFormat.ShowLinks);
 
Customizing exception output
In addition to shorten specific part of the exception, you can also override the default styling.
AnsiConsole.WriteException(ex, new ExceptionSettings
{
    Format = ExceptionFormats.ShortenEverything | ExceptionFormats.ShowLinks,
    Style = new ExceptionStyle
    {
        Exception = Style.WithForeground(Color.Grey),
        Message = Style.WithForeground(Color.White),
        NonEmphasized = Style.WithForeground(Color.Cornsilk1),
        Parenthesis = Style.WithForeground(Color.Cornsilk1),
        Method = Style.WithForeground(Color.Red),
        ParameterName = Style.WithForeground(Color.Cornsilk1),
        ParameterType = Style.WithForeground(Color.Red),
        Path = Style.WithForeground(Color.Red),
        LineNumber = Style.WithForeground(Color.Cornsilk1),
    }
});
