| 1 | // Licensed to the .NET Foundation under one or more agreements. |
| 2 | // The .NET Foundation licenses this file to you under the MIT license. |
| 3 | // See the LICENSE file in the project root for more information. |
| 4 | |
| 5 | |
| 6 | /* |
| 7 | * Hook IfFailThrow calls to do some logging when exceptions are thrown. |
| 8 | * |
| 9 | */ |
| 10 | |
| 11 | #ifndef __ZAPLOG_H__ |
| 12 | #define __ZAPLOG_H__ |
| 13 | |
| 14 | #undef IfFailThrow |
| 15 | #define IfFailThrow(x) \ |
| 16 | do { \ |
| 17 | HRESULT hrMacro = x; \ |
| 18 | if (FAILED(hrMacro)) { \ |
| 19 | /* don't embed file names in retail to save space and avoid IP */ \ |
| 20 | /* a findstr /n will allow you to locate it in a pinch */ \ |
| 21 | ThrowAndLog(hrMacro, INDEBUG_COMMA(#x) INDEBUG_COMMA(__FILE__) __LINE__); \ |
| 22 | } \ |
| 23 | } while(FALSE) |
| 24 | |
| 25 | inline void ThrowAndLog(HRESULT hr, INDEBUG_COMMA(__in_z const char * szMsg) INDEBUG_COMMA(__in_z const char * szFile) int lineNum) |
| 26 | { |
| 27 | WRAPPER_NO_CONTRACT; |
| 28 | |
| 29 | // Log failures when StressLog is on |
| 30 | static ConfigDWORD g_iStressLog; |
| 31 | BOOL bLog = g_iStressLog.val_DontUse_(CLRConfig::UNSUPPORTED_StressLog, 0); |
| 32 | if (bLog) |
| 33 | { |
| 34 | #ifdef _DEBUG |
| 35 | GetSvcLogger()->Printf("IfFailThrow about to throw in file %s line %d, msg = %s, hr: 0x%X\n" , szFile, lineNum, szMsg, hr); |
| 36 | #else |
| 37 | GetSvcLogger()->Printf("IfFailThrow about to throw on line %d. hr: 0x%X\n" , lineNum, hr); |
| 38 | #endif |
| 39 | } |
| 40 | |
| 41 | ThrowHR(hr); |
| 42 | } |
| 43 | |
| 44 | #endif // __ZAPLOG_H__ |
| 45 | |