Hello,
I can't understand why the try-catch block in one dialog box are not caught exceptions (in project VS2005 C++ WinForms .NET 2.0)
There is one form. Second form called from it by button. Call the ShowDialog method is framed by try-catch (Exception^ ex)
When you press button in the Form2 the new Exception is thrown but is not falls in catch, and leads to post UnhandledException Message.
This situation present in Debug and Release builds, but
during step-by-step debugging in VS catch wonderful works.
What should I do to make these exceptions are caught in runtime?
compil commandline DEBUG:
/Od /D "WIN32" /D "_DEBUG" /D "_UNICODE" /D "UNICODE" /FD /EHa /MDd /Yu"stdafx.h" /Fp"Debug\nie.pch" /Fo"Debug\\" /Fd"Debug\vc80.pdb" /W3 /nologo /c /Zi /clr:pure /TP /errorReport:prompt /FU ...
compil commandline RELEASE:
/O2 /GL /D "WIN32" /D "NDEBUG" /D "_UNICODE" /D "UNICODE" /FD /EHa /MD /Yu"stdafx.h" /Fp"Release\nie.pch" /Fo"Release\\" /Fd"Release\vc80.pdb" /W3 /nologo /c /Zi /clr:pure /TP /errorReport:prompt /FU ...
my test App:
#pragma once
#include "Form2.h"
namespace nie {
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
public ref class Form1 : public System::Windows::Forms::Form
{
public:
Form1(void)
{
InitializeComponent();
dialogForm2 = gcnew Form2;
}
protected:
~Form1()
{
if (components)
{
delete components;
}
}
private: System::Windows::Forms::Button^ buttonCallForm2;
protected:
private:
System::ComponentModel::Container ^components;
#pragma region Windows Form Designer generated code
void InitializeComponent(void)
{
this->buttonCallForm2 = (gcnew System::Windows::Forms::Button());
this->SuspendLayout();
...
}
#pragma endregion
private: Form2^ dialogForm2;
private: System::Void buttonCallForm2_Click(System::Object^ sender, System::EventArgs^ e) {
try
{
dialogForm2->ShowDialog();
MessageBox::Show(L"exit normal");
}
catch(Exception^ ex)
{
MessageBox::Show(ex->Message); }
catch(...)
{
MessageBox::Show(L"oops"); }
}
};
}
#pragma once
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
namespace nie {
public ref class Form2 : public System::Windows::Forms::Form
{
public:
Form2(void)
{
InitializeComponent();
}
protected:
~Form2()
{
if (components)
{
delete components;
}
}
private: System::Windows::Forms::Button^ buttonEx;
protected:
protected:
private:
System::ComponentModel::Container ^components;
#pragma region Windows Form Designer generated code
void InitializeComponent(void)
{
this->buttonEx = (gcnew System::Windows::Forms::Button());
this->SuspendLayout();
...
}
#pragma endregion
private: System::Void buttonEx_Click(System::Object^ sender, System::EventArgs^ e) {
throw (gcnew System::Exception(L"!!! TEST EXCEPTION !!!"));
}
};
}
Thanks for help!