@@ -229,154 +229,150 @@ static WCHAR *FormatError(DWORD code)
229229}
230230
231231#ifndef DONT_USE_SEH
232- void SetException (DWORD code , EXCEPTION_RECORD * pr )
232+ static void SetException (DWORD code , EXCEPTION_RECORD * pr )
233233{
234- WCHAR * lpMsgBuf ;
235- lpMsgBuf = FormatError (code );
236- if (lpMsgBuf ) {
237- PyErr_SetFromWindowsErr (code );
238- LocalFree (lpMsgBuf );
239- } else {
240- switch (code ) {
241- case EXCEPTION_ACCESS_VIOLATION :
242- /* The thread attempted to read from or write
243- to a virtual address for which it does not
244- have the appropriate access. */
245- if (pr -> ExceptionInformation [0 ] == 0 )
246- PyErr_Format (PyExc_WindowsError ,
247- "exception: access violation reading %p" ,
248- pr -> ExceptionInformation [1 ]);
249- else
250- PyErr_Format (PyExc_WindowsError ,
251- "exception: access violation writing %p" ,
252- pr -> ExceptionInformation [1 ]);
253- break ;
254- case EXCEPTION_BREAKPOINT :
255- /* A breakpoint was encountered. */
256- PyErr_SetString (PyExc_WindowsError ,
257- "exception: breakpoint encountered" );
258- break ;
259-
260- case EXCEPTION_DATATYPE_MISALIGNMENT :
261- /* The thread attempted to read or write data that is
262- misaligned on hardware that does not provide
263- alignment. For example, 16-bit values must be
264- aligned on 2-byte boundaries, 32-bit values on
265- 4-byte boundaries, and so on. */
266- PyErr_SetString (PyExc_WindowsError ,
267- "exception: datatype misalignment" );
268- break ;
269-
270- case EXCEPTION_SINGLE_STEP :
271- /* A trace trap or other single-instruction mechanism
272- signaled that one instruction has been executed. */
273- PyErr_SetString (PyExc_WindowsError ,
274- "exception: single step" );
275- break ;
276-
277- case EXCEPTION_ARRAY_BOUNDS_EXCEEDED :
278- /* The thread attempted to access an array element
279- that is out of bounds, and the underlying hardware
280- supports bounds checking. */
281- PyErr_SetString (PyExc_WindowsError ,
282- "exception: array bounds exceeded" );
283- break ;
284-
285- case EXCEPTION_FLT_DENORMAL_OPERAND :
286- /* One of the operands in a floating-point operation
287- is denormal. A denormal value is one that is too
288- small to represent as a standard floating-point
289- value. */
290- PyErr_SetString (PyExc_WindowsError ,
291- "exception: floating-point operand denormal" );
292- break ;
293-
294- case EXCEPTION_FLT_DIVIDE_BY_ZERO :
295- /* The thread attempted to divide a floating-point
296- value by a floating-point divisor of zero. */
297- PyErr_SetString (PyExc_WindowsError ,
298- "exception: float divide by zero" );
299- break ;
300-
301- case EXCEPTION_FLT_INEXACT_RESULT :
302- /* The result of a floating-point operation cannot be
303- represented exactly as a decimal fraction. */
304- PyErr_SetString (PyExc_WindowsError ,
305- "exception: float inexact" );
306- break ;
307-
308- case EXCEPTION_FLT_INVALID_OPERATION :
309- /* This exception represents any floating-point
310- exception not included in this list. */
311- PyErr_SetString (PyExc_WindowsError ,
312- "exception: float invalid operation" );
313- break ;
314-
315- case EXCEPTION_FLT_OVERFLOW :
316- /* The exponent of a floating-point operation is
317- greater than the magnitude allowed by the
318- corresponding type. */
319- PyErr_SetString (PyExc_WindowsError ,
320- "exception: float overflow" );
321- break ;
322-
323- case EXCEPTION_FLT_STACK_CHECK :
324- /* The stack overflowed or underflowed as the result
325- of a floating-point operation. */
326- PyErr_SetString (PyExc_WindowsError ,
327- "exception: stack over/underflow" );
328- break ;
329-
330- case EXCEPTION_STACK_OVERFLOW :
331- /* The stack overflowed or underflowed as the result
332- of a floating-point operation. */
333- PyErr_SetString (PyExc_WindowsError ,
334- "exception: stack overflow" );
335- break ;
336-
337- case EXCEPTION_FLT_UNDERFLOW :
338- /* The exponent of a floating-point operation is less
339- than the magnitude allowed by the corresponding
340- type. */
341- PyErr_SetString (PyExc_WindowsError ,
342- "exception: float underflow" );
343- break ;
344-
345- case EXCEPTION_INT_DIVIDE_BY_ZERO :
346- /* The thread attempted to divide an integer value by
347- an integer divisor of zero. */
348- PyErr_SetString (PyExc_WindowsError ,
349- "exception: integer divide by zero" );
350- break ;
351-
352- case EXCEPTION_INT_OVERFLOW :
353- /* The result of an integer operation caused a carry
354- out of the most significant bit of the result. */
355- PyErr_SetString (PyExc_WindowsError ,
356- "exception: integer overflow" );
357- break ;
358-
359- case EXCEPTION_PRIV_INSTRUCTION :
360- /* The thread attempted to execute an instruction
361- whose operation is not allowed in the current
362- machine mode. */
363- PyErr_SetString (PyExc_WindowsError ,
364- "exception: priviledged instruction" );
365- break ;
366-
367- case EXCEPTION_NONCONTINUABLE_EXCEPTION :
368- /* The thread attempted to continue execution after a
369- noncontinuable exception occurred. */
370- PyErr_SetString (PyExc_WindowsError ,
371- "exception: nocontinuable" );
372- break ;
373- default :
374- printf ("error %d\n" , code );
234+ /* The 'code' is a normal win32 error code so it could be handled by
235+ PyErr_SetFromWindowsErr(). However, for some errors, we have additional
236+ information not included in the error code. We handle those here and
237+ delegate all others to the generic function. */
238+ switch (code ) {
239+ case EXCEPTION_ACCESS_VIOLATION :
240+ /* The thread attempted to read from or write
241+ to a virtual address for which it does not
242+ have the appropriate access. */
243+ if (pr -> ExceptionInformation [0 ] == 0 )
375244 PyErr_Format (PyExc_WindowsError ,
376- "exception code 0x%08x" ,
377- code );
378- break ;
379- }
245+ "exception: access violation reading %p" ,
246+ pr -> ExceptionInformation [1 ]);
247+ else
248+ PyErr_Format (PyExc_WindowsError ,
249+ "exception: access violation writing %p" ,
250+ pr -> ExceptionInformation [1 ]);
251+ break ;
252+
253+ case EXCEPTION_BREAKPOINT :
254+ /* A breakpoint was encountered. */
255+ PyErr_SetString (PyExc_WindowsError ,
256+ "exception: breakpoint encountered" );
257+ break ;
258+
259+ case EXCEPTION_DATATYPE_MISALIGNMENT :
260+ /* The thread attempted to read or write data that is
261+ misaligned on hardware that does not provide
262+ alignment. For example, 16-bit values must be
263+ aligned on 2-byte boundaries, 32-bit values on
264+ 4-byte boundaries, and so on. */
265+ PyErr_SetString (PyExc_WindowsError ,
266+ "exception: datatype misalignment" );
267+ break ;
268+
269+ case EXCEPTION_SINGLE_STEP :
270+ /* A trace trap or other single-instruction mechanism
271+ signaled that one instruction has been executed. */
272+ PyErr_SetString (PyExc_WindowsError ,
273+ "exception: single step" );
274+ break ;
275+
276+ case EXCEPTION_ARRAY_BOUNDS_EXCEEDED :
277+ /* The thread attempted to access an array element
278+ that is out of bounds, and the underlying hardware
279+ supports bounds checking. */
280+ PyErr_SetString (PyExc_WindowsError ,
281+ "exception: array bounds exceeded" );
282+ break ;
283+
284+ case EXCEPTION_FLT_DENORMAL_OPERAND :
285+ /* One of the operands in a floating-point operation
286+ is denormal. A denormal value is one that is too
287+ small to represent as a standard floating-point
288+ value. */
289+ PyErr_SetString (PyExc_WindowsError ,
290+ "exception: floating-point operand denormal" );
291+ break ;
292+
293+ case EXCEPTION_FLT_DIVIDE_BY_ZERO :
294+ /* The thread attempted to divide a floating-point
295+ value by a floating-point divisor of zero. */
296+ PyErr_SetString (PyExc_WindowsError ,
297+ "exception: float divide by zero" );
298+ break ;
299+
300+ case EXCEPTION_FLT_INEXACT_RESULT :
301+ /* The result of a floating-point operation cannot be
302+ represented exactly as a decimal fraction. */
303+ PyErr_SetString (PyExc_WindowsError ,
304+ "exception: float inexact" );
305+ break ;
306+
307+ case EXCEPTION_FLT_INVALID_OPERATION :
308+ /* This exception represents any floating-point
309+ exception not included in this list. */
310+ PyErr_SetString (PyExc_WindowsError ,
311+ "exception: float invalid operation" );
312+ break ;
313+
314+ case EXCEPTION_FLT_OVERFLOW :
315+ /* The exponent of a floating-point operation is
316+ greater than the magnitude allowed by the
317+ corresponding type. */
318+ PyErr_SetString (PyExc_WindowsError ,
319+ "exception: float overflow" );
320+ break ;
321+
322+ case EXCEPTION_FLT_STACK_CHECK :
323+ /* The stack overflowed or underflowed as the result
324+ of a floating-point operation. */
325+ PyErr_SetString (PyExc_WindowsError ,
326+ "exception: stack over/underflow" );
327+ break ;
328+
329+ case EXCEPTION_STACK_OVERFLOW :
330+ /* The stack overflowed or underflowed as the result
331+ of a floating-point operation. */
332+ PyErr_SetString (PyExc_WindowsError ,
333+ "exception: stack overflow" );
334+ break ;
335+
336+ case EXCEPTION_FLT_UNDERFLOW :
337+ /* The exponent of a floating-point operation is less
338+ than the magnitude allowed by the corresponding
339+ type. */
340+ PyErr_SetString (PyExc_WindowsError ,
341+ "exception: float underflow" );
342+ break ;
343+
344+ case EXCEPTION_INT_DIVIDE_BY_ZERO :
345+ /* The thread attempted to divide an integer value by
346+ an integer divisor of zero. */
347+ PyErr_SetString (PyExc_WindowsError ,
348+ "exception: integer divide by zero" );
349+ break ;
350+
351+ case EXCEPTION_INT_OVERFLOW :
352+ /* The result of an integer operation caused a carry
353+ out of the most significant bit of the result. */
354+ PyErr_SetString (PyExc_WindowsError ,
355+ "exception: integer overflow" );
356+ break ;
357+
358+ case EXCEPTION_PRIV_INSTRUCTION :
359+ /* The thread attempted to execute an instruction
360+ whose operation is not allowed in the current
361+ machine mode. */
362+ PyErr_SetString (PyExc_WindowsError ,
363+ "exception: priviledged instruction" );
364+ break ;
365+
366+ case EXCEPTION_NONCONTINUABLE_EXCEPTION :
367+ /* The thread attempted to continue execution after a
368+ noncontinuable exception occurred. */
369+ PyErr_SetString (PyExc_WindowsError ,
370+ "exception: nocontinuable" );
371+ break ;
372+
373+ default :
374+ PyErr_SetFromWindowsErr (code );
375+ break ;
380376 }
381377}
382378
0 commit comments