From 3e8f85a68212faa81c82b904152a29a86cf92d19 Mon Sep 17 00:00:00 2001 From: Steve Lee Date: Mon, 28 Jan 2019 12:13:15 -0800 Subject: [PATCH] Enable catching NotImplementedException when calling into RawUI for members that are not implemented --- .../FormatAndOutput/out-console/ConsoleLineOutput.cs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/System.Management.Automation/FormatAndOutput/out-console/ConsoleLineOutput.cs b/src/System.Management.Automation/FormatAndOutput/out-console/ConsoleLineOutput.cs index ee6c17884e..1883c48962 100644 --- a/src/System.Management.Automation/FormatAndOutput/out-console/ConsoleLineOutput.cs +++ b/src/System.Management.Automation/FormatAndOutput/out-console/ConsoleLineOutput.cs @@ -5,6 +5,7 @@ // characters //#define TEST_MULTICELL_ON_SINGLE_CELL_LOCALE +using System; using System.Collections.Specialized; using System.Management.Automation; using System.Management.Automation.Internal; @@ -93,7 +94,7 @@ namespace Microsoft.PowerShell.Commands.Internal.Format { return _rawUserInterface.LengthInBufferCells(str, offset); } - catch (HostException) + catch (Exception ex) when (ex is HostException || ex is NotImplementedException) { // thrown when external host rawui is not implemented, in which case // we will fallback to the default value. @@ -108,7 +109,7 @@ namespace Microsoft.PowerShell.Commands.Internal.Format { return _rawUserInterface.LengthInBufferCells(str); } - catch (HostException) + catch (Exception ex) when (ex is HostException || ex is NotImplementedException) { // thrown when external host rawui is not implemented, in which case // we will fallback to the default value. @@ -123,7 +124,7 @@ namespace Microsoft.PowerShell.Commands.Internal.Format { return _rawUserInterface.LengthInBufferCells(character); } - catch (HostException) + catch (Exception ex) when (ex is HostException || ex is NotImplementedException) { // thrown when external host rawui is not implemented, in which case // we will fallback to the default value. @@ -178,7 +179,7 @@ namespace Microsoft.PowerShell.Commands.Internal.Format { return _forceNewLine ? raw.BufferSize.Width - 1 : raw.BufferSize.Width; } - catch (HostException) + catch (Exception ex) when (ex is HostException || ex is NotImplementedException) { // thrown when external host rawui is not implemented, in which case // we will fallback to the default value. @@ -204,7 +205,7 @@ namespace Microsoft.PowerShell.Commands.Internal.Format { return raw.WindowSize.Height; } - catch (HostException) + catch (Exception ex) when (ex is HostException || ex is NotImplementedException) { // thrown when external host rawui is not implemented, in which case // we will fallback to the default value.