I am invoking code that uses the BitmapData class from .NET. I hit something where I cannot find the final answer on Googlespace.
Since it seems that LockBits and UnlockBits should always be called in pairs, I use this:
System.Drawing.Imaging.BitmapData tempImageData = tempImage.LockBits( new System.Drawing.Rectangle(0, 0, tempImage.Width, tempImage.Height), System.Drawing.Imaging.ImageLockMode.ReadOnly, tempImage.PixelFormat); try { //use external library on the data }//Exception not handled here; throw to calling method finally { tempImage.UnlockBits(tempImageData); }
(I recently played using the using statement, which is very useful in C #, which gave me an idea that I should do this.) The problem is that even the MS documentation ( http://msdn.microsoft.com/ en-us / library / system.drawing.bitmap.unlockbits.aspx ) does not see that it is suitable for using the try-finally template.
Is the attempt - finally, necessary or free?
Update: I can end up catching and re-throwing the exception, since I don't know what it might be and didn't catch them before.
Thanks!
Chris source share