G
Guest
While developing the below code I noticed that exceptions were not working as
expected. An exception is thrown inside an XML import DLL and not being
caught inside the Main() code fragment, creating an unhandled exception
inside "theUI". Would anybody know why this is happening?
I thought the general rule for exceptions handling was the exception is
passed up the stack until the application handles it or the program
terminates?
Simplified code:-
--------------------------------------------------------------------------
Main code fragment
--------------------------------------------------------------------------
Form theUI = new Form();
try
{
if( theUI.ShowDialog() == DialogResult.OK )
{
// Success code
}
}
catch(Exception e)
{
// Exceptions catch all?
Error.ShowError("<Error message>");
return;
}
--------------------------------------------------------------------------
"theUI" code fragment
--------------------------------------------------------------------------
// UI button click event
private void Button_Click(object sender, System.EventArgs e)
{
string theDataFile = <wrong data file> // User selected wrong file
Import(theDataFile);
}
private void Import(string theDataFile)
{
Collection theCol = ImportTableXml(theDataFile); // Exception thrown
inside ImportTableXml()
}
expected. An exception is thrown inside an XML import DLL and not being
caught inside the Main() code fragment, creating an unhandled exception
inside "theUI". Would anybody know why this is happening?
I thought the general rule for exceptions handling was the exception is
passed up the stack until the application handles it or the program
terminates?
Simplified code:-
--------------------------------------------------------------------------
Main code fragment
--------------------------------------------------------------------------
Form theUI = new Form();
try
{
if( theUI.ShowDialog() == DialogResult.OK )
{
// Success code
}
}
catch(Exception e)
{
// Exceptions catch all?
Error.ShowError("<Error message>");
return;
}
--------------------------------------------------------------------------
"theUI" code fragment
--------------------------------------------------------------------------
// UI button click event
private void Button_Click(object sender, System.EventArgs e)
{
string theDataFile = <wrong data file> // User selected wrong file
Import(theDataFile);
}
private void Import(string theDataFile)
{
Collection theCol = ImportTableXml(theDataFile); // Exception thrown
inside ImportTableXml()
}