RE: Can I throw an exception from my managed callback?



Thanks. It appears several of the links you provided don't work.

I did notice the docs for ProcessTrace() and was expecting to receive a
return of ERROR_NOACCESS when the callback threw an exception. However I
didn't. My managed callback threw an exception, didn't include any exception
handlers, and yet the return from ProcessTrace() was SUCCESS.

--
Thanks,
Nick

nicknospamdu@xxxxxxxxxxxxxxxx
remove "nospam" change community. to msn.com


"Lingzhi Sun [MSFT]" wrote:

Hi Nick,

I am still performing research on the issue about how to make the
ProcessTrace API return corresponding error code, when managed callback
function throws an exception. I appreciate your patience. Besides,
could you please let me know the background information about why you want
the ProcessTrace API to return the error code? Maybe we can find other
workarounds which fit for your detailed concern. Here I'd like to discuss
this issue with you and provide you with a possible workaround.

Based on the MSDN documentation, if the native callback function throws an
exception, the ProcessTrace API returns ERROR_NOACCESS (Code: 998, Message:
Invalid access to memory location). For detail, please see
http://msdn.microsoft.com/en-us/library/aa364093.aspx and
http://msdn.microsoft.com/en-us/library/ms681388.aspx.

Based on my research on the managed codes, if the exception in managed
callback function is caught inside the callback function, the ProcessTrace
function returns zero (SUCCESS). If the managed callback function does
not catch the exception, the exception will be caught by the closest catch
block in the managed callstack.

If you want to deal with the managed exception correctly, you can use the
managed try/catch block to handle the exception. Here is a related blog
article, which contains a well-formed class EventTraceWatcher. You can
refer to this class on how to trace the ETW events in C#:
http://blogs.msdn.com/danielvl/archive/2009/02/02/how-to-consume-etw-events-
from-c.aspx.

If you have any other questions, please be free to let me know.


Regards,
Lingzhi Sun (v-micsun@xxxxxxxxxxxxxxxxxxxx, remove 'online.')
Microsoft Online Community Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
msdnmg@xxxxxxxxxxxxxx

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/en-us/subscriptions/aa948868.aspx#notifications.

MSDN Managed Newsgroup support offering is for non-urgent issues where an
initial response from the community or a Microsoft Support Engineer within
2 business day is acceptable. Please note that each follow up response may
take approximately 2 business days as the support professional working with
you may need further investigation to reach the most efficient resolution.
The offering is not appropriate for situations that require urgent,
real-time or phone-based interactions. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/en-us/subscriptions/aa948874.aspx
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.


.



Relevant Pages

  • Re: Handling unhandled exceptions
    ... Just as Jeroen pointed out, as a library, your responsibility is ... throwing the exception for bad condition. ... Microsoft Online Community Support ... Please feel free to let my manager know what you think of the ...
    (microsoft.public.dotnet.languages.vc)
  • Re: Step by Step skips large chunks of code
    ... I have several applications that are threaded and I use exception handling ... The debugger product team has already identified the root cause of this ... Microsoft Online Community Support ... You can send feedback directly to my manager at: ...
    (microsoft.public.vsnet.debugging)
  • RE: Exception on SQLDependency background thread
    ... Microsoft MSDN Online Support Lead ... You can send feedback directly to my manager at: ... nature are best handled working with a dedicated Microsoft Support Engineer ... been crashing and not going through any of my exception management code. ...
    (microsoft.public.dotnet.framework.adonet)
  • RE: Can I throw an exception from my managed callback?
    ... ProcessTrace API return corresponding error code, when managed callback ... function throws an exception. ... Microsoft Online Community Support ... You can send feedback directly to my manager at: ...
    (microsoft.public.dotnet.framework.interop)
  • RE: How to enumerate all events in an active circular ETW logfile?
    ... Using ProcessTrace on active circular file is something ... Microsoft Online Community Support ... You can send feedback directly to my manager at: ...
    (microsoft.public.win32.programmer.kernel)