what happens when you stop VS debugger?
Posted
by mare
on Stack Overflow
See other posts from Stack Overflow
or by mare
Published on 2010-04-20T13:10:41Z
Indexed on
2010/04/20
13:13 UTC
Read the original article
Hit count: 147
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));
using (
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.
© Stack Overflow or respective owner