Question

I have a quick question about some demo code from the directshownet samples. Is the following:

// Set the video to stream to pictureBox1
int hr;
hr = this.videoWindow.put_Owner(this.pictureBox1.Handle);
DsError.ThrowExceptionForHR(hr);

Preferable to:

// Set the video to stream to pictureBox1        
DsError.ThrowExceptionForHR(this.videoWindow.put_Owner(this.pictureBox1.Handle));

for any reason? If so, why? Cheers

Was it helpful?

Solution

Suppose the code is incorrect and the method fails with an error HRESULT. You likely will be debugging this code in the near future. In that situation, what do you prefer? Having to debug into ThrowExceptionForHR to examine the HRESULT that was returned, or putting a watch on the local hr?

I know which I would prefer.

Suppose the hr is only an error code sometimes. What do you prefer, putting a breakpoint inside ThrowExceptionForHR, or putting a conditional breakpoint on the caller that only breaks if the value stored in hr is an error code?

Again, I know which I would prefer.

Design your code to be easy to debug. You'll thank yourself later.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top