@@ -400,12 +400,20 @@ def _handle_exceptions(self):
400
400
"""Context guard to handle BASIC exceptions."""
401
401
try :
402
402
yield
403
- except error .Break :
403
+ except error .Break as e :
404
+ # ctrl-break stops foreground and background sound
404
405
self .sound .stop_all_sound ()
405
- self ._prompt = False
406
+ if not self .interpreter .run_mode and not e .stop :
407
+ self ._prompt = False
408
+ else :
409
+ self .interpreter .set_pointer (False )
410
+ # call _handle_error to write a message, etc.
411
+ self ._handle_error (e )
412
+ # override position of syntax error
413
+ if e .trapped_error_num == error .STX :
414
+ self ._syntax_error_edit_prompt (e .trapped_error_pos )
406
415
except error .BASICError as e :
407
416
self ._handle_error (e )
408
- self ._prompt = True
409
417
except error .Exit :
410
418
raise
411
419
@@ -416,13 +424,18 @@ def _handle_error(self, e):
416
424
self .console .write (e .get_message (self .program .get_line_number (e .pos )))
417
425
self .interpreter .set_parse_mode (False )
418
426
self .interpreter .input_mode = False
427
+ self ._prompt = True
419
428
# special case: syntax error
420
429
if e .err == error .STX :
421
- # for some reason, err is reset to zero by GW-BASIC in this case.
422
- self .interpreter .error_num = 0
423
- if e .pos is not None and e .pos != - 1 :
424
- # line edit gadget appears
425
- self ._edit_prompt = (self .program .get_line_number (e .pos ), e .pos + 1 )
430
+ self ._syntax_error_edit_prompt (e .pos )
431
+
432
+ def _syntax_error_edit_prompt (self , pos ):
433
+ """Show an EDIT prompt at the location of a syntax error."""
434
+ # for some reason, err is reset to zero by GW-BASIC in this case.
435
+ self .interpreter .error_num = 0
436
+ if pos is not None and pos != - 1 :
437
+ # line edit gadget appears
438
+ self ._edit_prompt = (self .program .get_line_number (pos ), pos + 1 )
426
439
427
440
###########################################################################
428
441
# callbacks
0 commit comments