As far as detecting the corruption, there is no exact way to do this, you can trap it in your Try/Catch.
I haven't tried compacting in .NET, but for sure if it is not successfull you will again trap it in the Try/Catch. ( Unless the method has its' own exception handling in which case you would take that route in your Catch.)