What is the best way to treat errors in calls like:
string myString = Marshal.PtrToStringUni(wParam);
Int32 myInt = Marshal.ReadInt32(lParam);
?
[edit]
Based on Hans Passant’s answer, I want to share the link to MS description
Thanks a lot!
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The best way here is the best way where ever you get an exception, don’t do anything. Windows sent you a bad message, you have no idea why. You cannot handle an exception if you have no clue what caused it and what the consequences might be. Swallowing it just causes your program to operate incorrectly without any hint to the user why. There is no way to test this scenario.
Don’t catch it, let it terminate your application.
Focus on writing a good event handler for AppDomain.CurrentDomain.UnhandledException instead.