File tree Expand file tree Collapse file tree 3 files changed +36
-3
lines changed Expand file tree Collapse file tree 3 files changed +36
-3
lines changed Original file line number Diff line number Diff line change @@ -748,6 +748,22 @@ def test_raise_exception(self):
748
748
3 ,
749
749
name )
750
750
751
+ @unittest .skipUnless (MS_WINDOWS , 'specific to Windows' )
752
+ def test_ignore_exception (self ):
753
+ for exc_code in (
754
+ 0xE06D7363 , # MSC exception ("Emsc")
755
+ 0xE0434352 , # COM Callable Runtime exception ("ECCR")
756
+ ):
757
+ code = f"""
758
+ import faulthandler
759
+ faulthandler.enable()
760
+ faulthandler._raise_exception({ exc_code } )
761
+ """
762
+ code = dedent (code )
763
+ output , exitcode = self .get_output (code )
764
+ self .assertEqual (output , [])
765
+ self .assertEqual (exitcode , exc_code )
766
+
751
767
@unittest .skipUnless (MS_WINDOWS , 'specific to Windows' )
752
768
def test_raise_nonfatal_exception (self ):
753
769
# These exceptions are not strictly errors. Letting
Original file line number Diff line number Diff line change
1
+ On Windows, faulthandler.enable() now ignores MSC and COM exceptions.
Original file line number Diff line number Diff line change @@ -360,16 +360,32 @@ faulthandler_fatal_error(int signum)
360
360
}
361
361
362
362
#ifdef MS_WINDOWS
363
+ static int
364
+ faulthandler_ignore_exception (DWORD code )
365
+ {
366
+ /* bpo-30557: ignore exceptions which are not errors */
367
+ if (!(code & 0x80000000 )) {
368
+ return 1 ;
369
+ }
370
+ /* bpo-31701: ignore MSC and COM exceptions
371
+ E0000000 + code */
372
+ if (code == 0xE06D7363 /* MSC exception ("Emsc") */
373
+ || code == 0xE0434352 /* COM Callable Runtime exception ("ECCR") */ ) {
374
+ return 1 ;
375
+ }
376
+ /* Interesting exception: log it with the Python traceback */
377
+ return 0 ;
378
+ }
379
+
363
380
static LONG WINAPI
364
381
faulthandler_exc_handler (struct _EXCEPTION_POINTERS * exc_info )
365
382
{
366
383
const int fd = fatal_error .fd ;
367
384
DWORD code = exc_info -> ExceptionRecord -> ExceptionCode ;
368
385
DWORD flags = exc_info -> ExceptionRecord -> ExceptionFlags ;
369
386
370
- /* bpo-30557: only log fatal exceptions */
371
- if (!(code & 0x80000000 )) {
372
- /* call the next exception handler */
387
+ if (faulthandler_ignore_exception (code )) {
388
+ /* ignore the exception: call the next exception handler */
373
389
return EXCEPTION_CONTINUE_SEARCH ;
374
390
}
375
391
You can’t perform that action at this time.
0 commit comments