views:

39

answers:

1

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.

A: 

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.

Noon Silk
This is from ASP.NET MVC application, should it end the process? At the moment, my browser window stays open. I have not configured it that way, it is like that by default.
mare
@mare: Here when I have Firefox as my default browser, it doesn't end the process. It used to with IE. I think there is probably a setting somewhere; but I generally prefer that it *doesn't* end the process, so I haven't looked into it.
Noon Silk
I can confirm that this is browser dependent at my side also.
mare