Click here to Skip to main content
15,897,273 members
Home / Discussions / C#
   

C#

 
GeneralRe: Unhandled exceptions on Model Form remains unhandled in the release build even if the call to the model form is wrapped up in the try….catch{ } block!!!!!! Pin
Cracked-Down4-Aug-09 23:53
Cracked-Down4-Aug-09 23:53 
AnswerRe: Unhandled exceptions on Model Form remains unhandled in the release build even if the call to the model form is wrapped up in the try….catch{ } block!!!!!! Pin
Luc Pattyn4-Aug-09 23:44
sitebuilderLuc Pattyn4-Aug-09 23:44 
GeneralRe: Unhandled exceptions on Model Form remains unhandled in the release build even if the call to the model form is wrapped up in the try….catch{ } block!!!!!! Pin
Christian Graus4-Aug-09 23:46
protectorChristian Graus4-Aug-09 23:46 
GeneralRe: Unhandled exceptions on Model Form remains unhandled in the release build even if the call to the model form is wrapped up in the try….catch{ } block!!!!!! Pin
Cracked-Down5-Aug-09 0:05
Cracked-Down5-Aug-09 0:05 
GeneralRe: Unhandled exceptions on Model Form remains unhandled in the release build even if the call to the model form is wrapped up in the try….catch{ } block!!!!!! Pin
Christian Graus5-Aug-09 0:17
protectorChristian Graus5-Aug-09 0:17 
AnswerRe: Unhandled exceptions on Model Form remains unhandled in the release build even if the call to the model form is wrapped up in the try….catch{ } block!!!!!! Pin
Moreno Airoldi5-Aug-09 0:48
Moreno Airoldi5-Aug-09 0:48 
GeneralRe: Unhandled exceptions on Model Form remains unhandled in the release build even if the call to the model form is wrapped up in the try….catch{ } block!!!!!! Pin
Cracked-Down5-Aug-09 1:03
Cracked-Down5-Aug-09 1:03 
GeneralRe: Unhandled exceptions on Model Form remains unhandled in the release build even if the call to the model form is wrapped up in the try….catch{ } block!!!!!! Pin
Moreno Airoldi5-Aug-09 2:44
Moreno Airoldi5-Aug-09 2:44 
Sorry I think I didn't make myself clear: what I mean is it's perfectly normal that the application, when run directly (i.e. running the exe file) crashes. But this will happen for both Debug and Release!

If you run the app inside the VS debugger, on the contrary, then it will behave differently: both Debug and Release versions will catch the exception and show the dialog box.

This happens because exception handling is slightly different while running the debugger.

Just to be sure I made the experiment myself just now, and I confirm what I said.

In order to capture the exception you must use a local try/catch block in the ModelDialog form.

There is no way I know of handling the exception the way you want to. I suggest your change your approach. Consider this (just a raw example):

C#
namespace ModelDialogExceptions
{
    public partial class ModelDialog : Form
    {
        public ModelDialog()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                // this is just for test, of course
                throw new System.IO.FileNotFoundException("");

                // when all is fine...
                DialogResult = DialogResult.OK;
            }
            catch (Exception)
            {
                // when it goes wrong...
                DialogResult = DialogResult.Abort;
            }
        }

        internal static bool GetMyFile()
        {
            ModelDialog md = new ModelDialog();
            switch (md.ShowDialog())
            {
                case DialogResult.OK:
                    return true;
                case DialogResult.Abort:
                    throw new ApplicationException("Operation aborted, an exception may have been thrown.");
                case DialogResult.Cancel:
                    throw new ApplicationException("Cancelled by user.");
                default:
                    throw new ApplicationException("Unknown error.");
            }
        }
    }
}


C#
namespace ModelDialogExceptions
{
    public partial class MainForm : Form
    {
        public MainForm()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                if (ModelDialog.GetMyFile())
                {
                    MessageBox.Show("All ok!");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
    }
}


2+2=5 for very large amounts of 2
(always loved that one hehe!)

GeneralRe: Unhandled exceptions on Model Form remains unhandled in the release build even if the call to the model form is wrapped up in the try….catch{ } block!!!!!! Pin
Cracked-Down5-Aug-09 18:45
Cracked-Down5-Aug-09 18:45 
GeneralRe: Unhandled exceptions on Model Form remains unhandled in the release build even if the call to the model form is wrapped up in the try….catch{ } block!!!!!! Pin
Moreno Airoldi5-Aug-09 23:19
Moreno Airoldi5-Aug-09 23:19 
GeneralRe: Unhandled exceptions on Model Form remains unhandled in the release build even if the call to the model form is wrapped up in the try….catch{ } block!!!!!! Pin
Cracked-Down6-Aug-09 0:20
Cracked-Down6-Aug-09 0:20 
GeneralRe: Unhandled exceptions on Model Form remains unhandled in the release build even if the call to the model form is wrapped up in the try….catch{ } block!!!!!! Pin
Moreno Airoldi6-Aug-09 0:26
Moreno Airoldi6-Aug-09 0:26 
Question"NC code" text file parsing with C# Pin
kirazercan4-Aug-09 22:14
kirazercan4-Aug-09 22:14 
AnswerRe: "NC code" text file parsing with C# Pin
Christian Graus4-Aug-09 22:25
protectorChristian Graus4-Aug-09 22:25 
Question[Message Deleted] Pin
engg_sukreet4-Aug-09 22:08
engg_sukreet4-Aug-09 22:08 
AnswerRe: hi Pin
Christian Graus4-Aug-09 22:13
protectorChristian Graus4-Aug-09 22:13 
AnswerRe: hi Pin
OriginalGriff4-Aug-09 22:16
mveOriginalGriff4-Aug-09 22:16 
AnswerRe: hi Pin
stancrm4-Aug-09 22:55
stancrm4-Aug-09 22:55 
GeneralRe: hi Pin
tomseyes4-Aug-09 23:13
tomseyes4-Aug-09 23:13 
Question[Message Deleted] Pin
engg_sukreet4-Aug-09 22:05
engg_sukreet4-Aug-09 22:05 
AnswerRe: Hello Guys Pin
Christian Graus4-Aug-09 22:14
protectorChristian Graus4-Aug-09 22:14 
AnswerRe: Hello Guys Pin
stancrm4-Aug-09 22:54
stancrm4-Aug-09 22:54 
GeneralRe: Hello Guys Pin
OriginalGriff4-Aug-09 22:57
mveOriginalGriff4-Aug-09 22:57 
GeneralRe: Hello Guys Pin
Mycroft Holmes4-Aug-09 23:18
professionalMycroft Holmes4-Aug-09 23:18 
GeneralRe: Hello Guys Pin
Amangang5-Aug-09 2:21
Amangang5-Aug-09 2:21 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.