If I have a line like this
ContentRepository.Update(existing);
that goes into datastore repository to update some object and I have a try..catch block in this Update function like this:
string file = XmlProvider.DataStorePhysicalPath + o.GetType().Name + Path.DirectorySeparatorChar + o.Slug + ".xml";
DataContractSerializer dcs = new DataContractSerializer(typeof (BaseContentObject));
开发者_如何学JAVAusing (
XmlDictionaryWriter myWriter =
XmlDictionaryWriter.CreateTextWriter(new FileStream(file, FileMode.Truncate, FileAccess.Write),
Encoding.UTF8))
{
try
{
dcs.WriteObject(myWriter, o);
myWriter.Close();
}
catch (Exception)
{
// if anything goes wrong, delete the created file
if (File.Exists(file))
File.Delete(file);
if(myWriter.WriteState!=WriteState.Closed)
myWriter.Close();
}
}
then why would Visual Studio go on with calling Update() if I click "Stop" in debugging session on the above line?
For instance, I came to that line by going line by line pressing F10 and now I'm on that line which is colored yellow and I press Stop.
Apparently what happens is, VS goes to execute the Update() method and somehow figures out something gone wrong and goes into "catch" and deletes the file, which is wrong, because I want my catch to work when there is a true exception not when I debug a program and force to stop it.
It depends if the debugger detaching ends the process. If it doesn't, then the program will continue to run. If it does, then it won't.
精彩评论