@@ -251,8 +251,8 @@ private bool BreakHandler(ConsoleBreakSignal signal)
251251 /// <returns>The complete command line.</returns>
252252 public static string ReadLine ( Runspace runspace , EngineIntrinsics engineIntrinsics )
253253 {
254- var console1 = _singleton . _console ;
255- _singleton . _prePSReadlineConsoleMode = console1 . GetConsoleInputMode ( ) ;
254+ var console = _singleton . _console ;
255+ _singleton . _prePSReadlineConsoleMode = console . GetConsoleInputMode ( ) ;
256256 bool firstTime = true ;
257257 while ( true )
258258 {
@@ -265,11 +265,11 @@ public static string ReadLine(Runspace runspace, EngineIntrinsics engineIntrinsi
265265 // ENABLE_MOUSE_INPUT - mouse events
266266 // ENABLE_WINDOW_INPUT - window resize events
267267 var mode = _singleton . _prePSReadlineConsoleMode &
268- ~ ( NativeMethods . ENABLE_PROCESSED_INPUT |
269- NativeMethods . ENABLE_LINE_INPUT |
270- NativeMethods . ENABLE_WINDOW_INPUT |
271- NativeMethods . ENABLE_MOUSE_INPUT ) ;
272- console1 . SetConsoleInputMode ( mode ) ;
268+ ~ ( NativeMethods . ENABLE_PROCESSED_INPUT |
269+ NativeMethods . ENABLE_LINE_INPUT |
270+ NativeMethods . ENABLE_WINDOW_INPUT |
271+ NativeMethods . ENABLE_MOUSE_INPUT ) ;
272+ console . SetConsoleInputMode ( mode ) ;
273273
274274 if ( firstTime )
275275 {
@@ -288,6 +288,19 @@ public static string ReadLine(Runspace runspace, EngineIntrinsics engineIntrinsi
288288 {
289289 return "exit" ;
290290 }
291+ catch ( CustomHandlerException e )
292+ {
293+ var oldColor = console . ForegroundColor ;
294+ console . ForegroundColor = ConsoleColor . Red ;
295+ console . WriteLine (
296+ string . Format ( CultureInfo . CurrentUICulture , PSReadLineResources . OopsCustomHandlerException , e . InnerException . Message ) ) ;
297+ console . ForegroundColor = oldColor ;
298+
299+ var lineBeforeCrash = _singleton . _buffer . ToString ( ) ;
300+ _singleton . Initialize ( runspace , _singleton . _engineIntrinsics ) ;
301+ InvokePrompt ( ) ;
302+ Insert ( lineBeforeCrash ) ;
303+ }
291304 catch ( Exception e )
292305 {
293306 // If we're running tests, just throw.
@@ -300,7 +313,6 @@ public static string ReadLine(Runspace runspace, EngineIntrinsics engineIntrinsi
300313 {
301314 e = e . InnerException ;
302315 }
303- var console = console1 ;
304316 var oldColor = console . ForegroundColor ;
305317 console . ForegroundColor = ConsoleColor . Red ;
306318 console . WriteLine ( PSReadLineResources . OopsAnErrorMessage1 ) ;
@@ -318,18 +330,17 @@ public static string ReadLine(Runspace runspace, EngineIntrinsics engineIntrinsi
318330 // Make it a little easier to see the keys
319331 sb . Append ( '\n ' ) ;
320332 }
321- // TODO: print non-default function bindings and script blocks
322333 }
323334
324335 console . WriteLine ( string . Format ( CultureInfo . CurrentUICulture , PSReadLineResources . OopsAnErrorMessage2 , _lastNKeys . Count , sb , e ) ) ;
325336 var lineBeforeCrash = _singleton . _buffer . ToString ( ) ;
326- _singleton . Initialize ( runspace , _singleton . _engineIntrinsics ) ;
337+ _singleton . Initialize ( runspace , _singleton . _engineIntrinsics ) ;
327338 InvokePrompt ( ) ;
328339 Insert ( lineBeforeCrash ) ;
329340 }
330341 finally
331342 {
332- console1 . SetConsoleInputMode ( _singleton . _prePSReadlineConsoleMode ) ;
343+ console . SetConsoleInputMode ( _singleton . _prePSReadlineConsoleMode ) ;
333344 }
334345 }
335346 }
0 commit comments