7
7
8
8
#include " debugutil.h"
9
9
10
- inline VOID ReportUntypedException ()
10
+ #define LOCATION_INFO_ENABLED TRUE
11
+
12
+ #if LOCATION_INFO_ENABLED
13
+ #define LOCATION_FORMAT " %s:%d "
14
+ #define LOCATION_ARGUMENTS_ONLY _In_opt_ PCSTR fileName, unsigned int lineNumber
15
+ #define LOCATION_ARGUMENTS LOCATION_ARGUMENTS_ONLY,
16
+ #define LOCATION_CALL_ONLY fileName, lineNumber
17
+ #define LOCATION_CALL LOCATION_CALL_ONLY,
18
+ #define LOCATION_INFO __FILE__, __LINE__
19
+ #else
20
+ #define LOCATION_FORMAT
21
+ #define LOCATION_ARGUMENTS_ONLY
22
+ #define LOCATION_ARGUMENTS
23
+ #define LOCATION_CALL_ONLY
24
+ #define LOCATION_CALL
25
+ #define LOCATION_INFO
26
+ #endif
27
+
28
+ #define OBSERVE_CAUGHT_EXCEPTION () CaughtExceptionHResult(LOCATION_INFO);
29
+ #define RETURN_CAUGHT_EXCEPTION () return CaughtExceptionHResult(LOCATION_INFO);
30
+ #define CATCH_RETURN () catch (...) { RETURN_CAUGHT_EXCEPTION (); }
31
+ #define THROW_IF_NULL_ALLOC (ptr ) Throw_IfNullAlloc(ptr)
32
+ #define RETURN_IF_FAILED (hr ) do { HRESULT __hrRet = hr; if (FAILED (__hrRet)) { LogHResultFailed (LOCATION_INFO, __hrRet); return __hrRet; }} while (0 , 0 )
33
+ #define FINISHED_IF_FAILED (hrr ) do { HRESULT __hrRet = hrr; if (FAILED (__hrRet)) { LogHResultFailed (LOCATION_INFO, __hrRet); hr = __hrRet; goto Finished; }} while (0 , 0 )
34
+ #define LOG_IF_FAILED (hr ) LogHResultFailed(LOCATION_INFO, hr)
35
+ #define SUCCEEDED_LOG (hr ) SUCCEEDED(LOG_IF_FAILED(hr))
36
+ #define FAILED_LOG (hr ) FAILED(LOG_IF_FAILED(hr))
37
+
38
+ __declspec (noinline) inline VOID ReportUntypedException(LOCATION_ARGUMENTS_ONLY)
39
+ {
40
+ DebugPrintf (ASPNETCORE_DEBUG_FLAG_ERROR, LOCATION_FORMAT " Unhandled non-standard exception" , LOCATION_CALL_ONLY);
41
+ }
42
+
43
+ __declspec (noinline) inline VOID ReportException(LOCATION_ARGUMENTS std::exception & exception )
11
44
{
12
- DebugPrint (ASPNETCORE_DEBUG_FLAG_ERROR, " Unhandled non-standard exception" );
45
+ DebugPrintf (ASPNETCORE_DEBUG_FLAG_ERROR, LOCATION_FORMAT " Unhandled exception: %s " , LOCATION_CALL exception . what () );
13
46
}
14
47
15
- inline VOID ReportException (std:: exception & exception )
48
+ __declspec (noinline) inline HRESULT LogHResultFailed(LOCATION_ARGUMENTS HRESULT hr )
16
49
{
17
- DebugPrintf (ASPNETCORE_DEBUG_FLAG_ERROR, " Unhandled exception: %s" , exception .what ());
50
+ if (FAILED (hr))
51
+ {
52
+ DebugPrintf (ASPNETCORE_DEBUG_FLAG_ERROR, " Failed HRESULT returned: 0x%x at " LOCATION_FORMAT, hr, LOCATION_CALL_ONLY);
53
+ }
54
+ return hr;
18
55
}
19
56
20
- inline __declspec (noinline) HRESULT CaughtExceptionHResult()
57
+ __declspec (noinline) inline HRESULT CaughtExceptionHResult(LOCATION_ARGUMENTS_ONLY )
21
58
{
22
59
try
23
60
{
@@ -29,17 +66,17 @@ inline __declspec(noinline) HRESULT CaughtExceptionHResult()
29
66
}
30
67
catch (std::system_error& exception )
31
68
{
32
- ReportException (exception );
69
+ ReportException (LOCATION_CALL exception );
33
70
return exception .code ().value ();
34
71
}
35
72
catch (std::exception & exception )
36
73
{
37
- ReportException (exception );
74
+ ReportException (LOCATION_CALL exception );
38
75
return HRESULT_FROM_WIN32 (ERROR_UNHANDLED_EXCEPTION);
39
76
}
40
77
catch (...)
41
78
{
42
- ReportUntypedException ();
79
+ ReportUntypedException (LOCATION_CALL_ONLY );
43
80
return HRESULT_FROM_WIN32 (ERROR_UNHANDLED_EXCEPTION);
44
81
}
45
82
}
@@ -52,8 +89,3 @@ template <typename PointerT> auto Throw_IfNullAlloc(PointerT pointer)
52
89
}
53
90
return pointer;
54
91
}
55
-
56
-
57
- #define RETURN_CAUGHT_EXCEPTION () return CaughtExceptionHResult();
58
- #define CATCH_RETURN () catch (...) { RETURN_CAUGHT_EXCEPTION (); }
59
- #define THROW_IF_NULL_ALLOC (ptr ) Throw_IfNullAlloc(ptr)
0 commit comments