0
Reply

Why is this exception caught in VS but not in exe?!

clive908

clive908

Nov 23 2005 11:37 AM
1.8k
I have a program which puts progress info in a listbox as it runs. Based on this, the user may decide to stop at any time. To make this easy, I added a stop button which throws an exception which I catch. The wierd thing is, inside Visual Studio, it works as expected. The loop stops and no exception is displayed because I catch my own exception. Outside of Visual Studio, it raises and displays an exception which either lets me continue or close the program! Why?! Here is a cut-down version of what I am doing: private void StartLoopButton_Click(object sender, System.EventArgs e) { while (true) { try { //Give the applicatio a chance to see the exception Application.DoEvents(); } catch (CancelExportException) { break; } } } private void ThrowExceptionButton_Click(object sender, System.EventArgs e) { throw new CancelExportException(); } ... /// /// My exception; raised when user wishes to stop the export. /// public class CancelExportException : ApplicationException {}