catching first chance exception question
Feb. 26, 2004
10:28 p.m.
I'm looking at how windows deals with invalid parameters in some of the winmm functions and it raises some questions. Sometimes they will check the parameters and return an error code and sometimes they will let a bad parameter cause a first-chance exception and catch it and return an error code. Is it ok to do a simple NULL pointer check and return an error rather than letting it cause an exception and catching it? If not, what's the best way to catch the exception and return the proper error code?
February 2004
12:18 p.m.
Robert Reif a écrit : > I'm looking at how windows deals with invalid > parameters in some of the winmm functions and > it raises some questions. Sometimes they will check > the parameters and return an error code and > sometimes they will let a bad parameter cause > a first-chance exception and catch it and return > an error code. > > Is it ok to do a simple NULL pointer check and return an > error rather than letting it cause an exception and catching > it? If not, what's the best way to catch the exception and > return the proper error code? the normal rule of thumbs is: - don't use exception unless you have to (ie, we have a clear case of an application requiring that feature) => first implementation should be only based on NULL pointer testing - if you need to go further, then setting an exception handler is the thing to do (using IsBadReadPtr or IsBadWritePtr is a not 100% safe, especially in multi-threaded environments) A+
8062
Age (days ago)
8062
Last active (days ago)
1 comments
2 participants
participants (2)
-
Eric Pouech -
Robert Reif