File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -748,6 +748,22 @@ def test_raise_exception(self):
748748 3 ,
749749 name )
750750
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+
751767 @unittest .skipUnless (MS_WINDOWS , 'specific to Windows' )
752768 def test_raise_nonfatal_exception (self ):
753769 # 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)
360360}
361361
362362#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+
363380static LONG WINAPI
364381faulthandler_exc_handler (struct _EXCEPTION_POINTERS * exc_info )
365382{
366383 const int fd = fatal_error .fd ;
367384 DWORD code = exc_info -> ExceptionRecord -> ExceptionCode ;
368385 DWORD flags = exc_info -> ExceptionRecord -> ExceptionFlags ;
369386
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 */
373389 return EXCEPTION_CONTINUE_SEARCH ;
374390 }
375391
You can’t perform that action at this time.
0 commit comments