mirror of
				https://github.com/nsnail/spectre.console.git
				synced 2025-11-04 10:35:27 +08:00 
			
		
		
		
	Add various exception improvements
This commit is contained in:
		
				
					committed by
					
						
						Patrik Svensson
					
				
			
			
				
	
			
			
			
						parent
						
							39a8588dc3
						
					
				
				
					commit
					68e92f3365
				
			@@ -17,5 +17,16 @@ namespace Spectre.Console
 | 
			
		||||
        {
 | 
			
		||||
            Render(console, exception.GetRenderable(format));
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Writes an exception to the console.
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        /// <param name="console">The console.</param>
 | 
			
		||||
        /// <param name="exception">The exception to write to the console.</param>
 | 
			
		||||
        /// <param name="settings">The exception settings.</param>
 | 
			
		||||
        public static void WriteException(this IAnsiConsole console, Exception exception, ExceptionSettings settings)
 | 
			
		||||
        {
 | 
			
		||||
            Render(console, exception.GetRenderable(settings));
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -16,7 +16,36 @@ namespace Spectre.Console
 | 
			
		||||
        /// <returns>A <see cref="IRenderable"/> representing the exception.</returns>
 | 
			
		||||
        public static IRenderable GetRenderable(this Exception exception, ExceptionFormats format = ExceptionFormats.Default)
 | 
			
		||||
        {
 | 
			
		||||
            return ExceptionFormatter.Format(exception, format);
 | 
			
		||||
            if (exception is null)
 | 
			
		||||
            {
 | 
			
		||||
                throw new ArgumentNullException(nameof(exception));
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            return GetRenderable(exception, new ExceptionSettings
 | 
			
		||||
            {
 | 
			
		||||
                Format = format,
 | 
			
		||||
            });
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Gets a <see cref="IRenderable"/> representation of the exception.
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        /// <param name="exception">The exception to format.</param>
 | 
			
		||||
        /// <param name="settings">The exception settings.</param>
 | 
			
		||||
        /// <returns>A <see cref="IRenderable"/> representing the exception.</returns>
 | 
			
		||||
        public static IRenderable GetRenderable(this Exception exception, ExceptionSettings settings)
 | 
			
		||||
        {
 | 
			
		||||
            if (exception is null)
 | 
			
		||||
            {
 | 
			
		||||
                throw new ArgumentNullException(nameof(exception));
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            if (settings is null)
 | 
			
		||||
            {
 | 
			
		||||
                throw new ArgumentNullException(nameof(settings));
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            return ExceptionFormatter.Format(exception, settings);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user