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()
} 6 1694
Hi,
Are you using threads?
I just did a quick test , a win app with two forms, one call the other, the
second has a button and it raise an exception, it's correctly caught in the
first form:
//form 1:
private void button1_Click(object sender, System.EventArgs e)
{
try
{
new Form2().ShowDialog();
}
catch(Exception ee)
{
MessageBox.Show( ee.Message);
}
}
//form 2:
private void button1_Click(object sender, System.EventArgs e)
{
throw new Exception("text");
}
Cheers,
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
"Nick Reeves" <Ni********@discussions.microsoft.com> wrote in message
news:F5**********************************@microsof t.com... 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() }
Hello Ignacio,
No I'm not using threading. I don't think you'll able to replicate it using
simple test code, "as it works like it says on the tin". In my example the
main code fragment is called from a (legacy) C++ EXE/DLL's through COM, which
I think maybe influencing the exception handling somehow? It's the first time
I've ever seen this behaviour.
My solution is to put the exception handling inside the dialog, which
unfortunately makes it a bit clunky.
Cheers,
Nick
"Ignacio Machin ( .NET/ C# MVP )" wrote: Hi,
Are you using threads?
I just did a quick test , a win app with two forms, one call the other, the second has a button and it raise an exception, it's correctly caught in the first form:
//form 1: private void button1_Click(object sender, System.EventArgs e) { try { new Form2().ShowDialog(); } catch(Exception ee) { MessageBox.Show( ee.Message); } }
//form 2: private void button1_Click(object sender, System.EventArgs e) { throw new Exception("text"); }
Cheers,
-- Ignacio Machin, ignacio.machin AT dot.state.fl.us Florida Department Of Transportation
"Nick Reeves" <Ni********@discussions.microsoft.com> wrote in message news:F5**********************************@microsof t.com... 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() }
why not try putting an event handler on the Application.ThreadException
event and see what happens http://msdn.microsoft.com/library/de...ptiontopic.asp
HTH
Ollie Riches
"Nick Reeves" <Ni********@discussions.microsoft.com> wrote in message
news:36**********************************@microsof t.com... Hello Ignacio,
No I'm not using threading. I don't think you'll able to replicate it using simple test code, "as it works like it says on the tin". In my example the main code fragment is called from a (legacy) C++ EXE/DLL's through COM, which I think maybe influencing the exception handling somehow? It's the first time I've ever seen this behaviour.
My solution is to put the exception handling inside the dialog, which unfortunately makes it a bit clunky.
Cheers, Nick
"Ignacio Machin ( .NET/ C# MVP )" wrote:
Hi,
Are you using threads?
I just did a quick test , a win app with two forms, one call the other, the second has a button and it raise an exception, it's correctly caught in the first form:
//form 1: private void button1_Click(object sender, System.EventArgs e) { try { new Form2().ShowDialog(); } catch(Exception ee) { MessageBox.Show( ee.Message); } }
//form 2: private void button1_Click(object sender, System.EventArgs e) { throw new Exception("text"); }
Cheers,
-- Ignacio Machin, ignacio.machin AT dot.state.fl.us Florida Department Of Transportation
"Nick Reeves" <Ni********@discussions.microsoft.com> wrote in message news:F5**********************************@microsof t.com... > 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() > } > > >
Thanks Ollie,
I did think about doing this but I stopped in my tracks after debugging, I
will explain. When debugging I found that the exception does not get back to
the calling function (which is very strange). I get the .Net unhandled
exception message within the dialog with a option to continue, clicking on
continue the dialog code continues to execute normally.
Do you think this method would still handle this?
Cheers
"Ollie Riches" wrote: why not try putting an event handler on the Application.ThreadException event and see what happens
http://msdn.microsoft.com/library/de...ptiontopic.asp
HTH
Ollie Riches
"Nick Reeves" <Ni********@discussions.microsoft.com> wrote in message news:36**********************************@microsof t.com... Hello Ignacio,
No I'm not using threading. I don't think you'll able to replicate it using simple test code, "as it works like it says on the tin". In my example the main code fragment is called from a (legacy) C++ EXE/DLL's through COM, which I think maybe influencing the exception handling somehow? It's the first time I've ever seen this behaviour.
My solution is to put the exception handling inside the dialog, which unfortunately makes it a bit clunky.
Cheers, Nick
"Ignacio Machin ( .NET/ C# MVP )" wrote:
Hi,
Are you using threads?
I just did a quick test , a win app with two forms, one call the other, the second has a button and it raise an exception, it's correctly caught in the first form:
//form 1: private void button1_Click(object sender, System.EventArgs e) { try { new Form2().ShowDialog(); } catch(Exception ee) { MessageBox.Show( ee.Message); } }
//form 2: private void button1_Click(object sender, System.EventArgs e) { throw new Exception("text"); }
Cheers,
-- Ignacio Machin, ignacio.machin AT dot.state.fl.us Florida Department Of Transportation
"Nick Reeves" <Ni********@discussions.microsoft.com> wrote in message news:F5**********************************@microsof t.com... > 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() > } > > >
Are you running with 'Break into the debugger' switched on for all
exceptions in visual studio?
Ollie Riches
"Nick Reeves" <Ni********@discussions.microsoft.com> wrote in message
news:F9**********************************@microsof t.com... Thanks Ollie,
I did think about doing this but I stopped in my tracks after debugging, I will explain. When debugging I found that the exception does not get back to the calling function (which is very strange). I get the .Net unhandled exception message within the dialog with a option to continue, clicking on continue the dialog code continues to execute normally.
Do you think this method would still handle this?
Cheers
"Ollie Riches" wrote:
why not try putting an event handler on the Application.ThreadException event and see what happens
http://msdn.microsoft.com/library/de...ptiontopic.asp
HTH
Ollie Riches
"Nick Reeves" <Ni********@discussions.microsoft.com> wrote in message news:36**********************************@microsof t.com... > Hello Ignacio, > > No I'm not using threading. I don't think you'll able to replicate it > using > simple test code, "as it works like it says on the tin". In my example > the > main code fragment is called from a (legacy) C++ EXE/DLL's through COM, > which > I think maybe influencing the exception handling somehow? It's the > first > time > I've ever seen this behaviour. > > My solution is to put the exception handling inside the dialog, which > unfortunately makes it a bit clunky. > > Cheers, > Nick > > "Ignacio Machin ( .NET/ C# MVP )" wrote: > >> Hi, >> >> >> Are you using threads? >> >> I just did a quick test , a win app with two forms, one call the >> other, >> the >> second has a button and it raise an exception, it's correctly caught >> in >> the >> first form: >> >> //form 1: >> private void button1_Click(object sender, System.EventArgs e) >> { >> try >> { >> new Form2().ShowDialog(); >> } >> catch(Exception ee) >> { >> MessageBox.Show( ee.Message); >> } >> } >> >> >> //form 2: >> private void button1_Click(object sender, System.EventArgs e) >> { >> throw new Exception("text"); >> } >> >> >> Cheers, >> >> -- >> Ignacio Machin, >> ignacio.machin AT dot.state.fl.us >> Florida Department Of Transportation >> >> "Nick Reeves" <Ni********@discussions.microsoft.com> wrote in message >> news:F5**********************************@microsof t.com... >> > 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() >> > } >> > >> > >> > >> >> >>
No I wasn't, but I have tried this and it gives the same result.
Unfortunately the project dead line is looming at the end of this week and I
can not spend any more time on the matter. Also because of the nature of our
setup i.e. C++ main app calling down to .Net through COM, I think this
problem is going to be too difficult to diagnose remotely. I'm convinced its
something to do with .Net wrapped by COM. Eventually we'll move all the
legacy code into the .Net layer and this problem will disappear.
Many thanks
Nick
"Ollie Riches" wrote: Are you running with 'Break into the debugger' switched on for all exceptions in visual studio?
Ollie Riches
"Nick Reeves" <Ni********@discussions.microsoft.com> wrote in message news:F9**********************************@microsof t.com... Thanks Ollie,
I did think about doing this but I stopped in my tracks after debugging, I will explain. When debugging I found that the exception does not get back to the calling function (which is very strange). I get the .Net unhandled exception message within the dialog with a option to continue, clicking on continue the dialog code continues to execute normally.
Do you think this method would still handle this?
Cheers
"Ollie Riches" wrote:
why not try putting an event handler on the Application.ThreadException event and see what happens
http://msdn.microsoft.com/library/de...ptiontopic.asp
HTH
Ollie Riches
"Nick Reeves" <Ni********@discussions.microsoft.com> wrote in message news:36**********************************@microsof t.com... > Hello Ignacio, > > No I'm not using threading. I don't think you'll able to replicate it > using > simple test code, "as it works like it says on the tin". In my example > the > main code fragment is called from a (legacy) C++ EXE/DLL's through COM, > which > I think maybe influencing the exception handling somehow? It's the > first > time > I've ever seen this behaviour. > > My solution is to put the exception handling inside the dialog, which > unfortunately makes it a bit clunky. > > Cheers, > Nick > > "Ignacio Machin ( .NET/ C# MVP )" wrote: > >> Hi, >> >> >> Are you using threads? >> >> I just did a quick test , a win app with two forms, one call the >> other, >> the >> second has a button and it raise an exception, it's correctly caught >> in >> the >> first form: >> >> //form 1: >> private void button1_Click(object sender, System.EventArgs e) >> { >> try >> { >> new Form2().ShowDialog(); >> } >> catch(Exception ee) >> { >> MessageBox.Show( ee.Message); >> } >> } >> >> >> //form 2: >> private void button1_Click(object sender, System.EventArgs e) >> { >> throw new Exception("text"); >> } >> >> >> Cheers, >> >> -- >> Ignacio Machin, >> ignacio.machin AT dot.state.fl.us >> Florida Department Of Transportation >> >> "Nick Reeves" <Ni********@discussions.microsoft.com> wrote in message >> news:F5**********************************@microsof t.com... >> > 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() >> > } >> > >> > >> > >> >> >> This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Viktor Lundström |
last post by:
Hi!
I recently decided to write a streambuf which handles streamed
IO to a device (ie. a socket).
Now, in an effort to move away from C-style IO error handling
(ie. if(read(..) == -1) ...), I...
|
by: cody |
last post by:
public DateTime Value
{
get
{
try
{
return new DateTime(int.Parse(tbYear.Text), int.Parse(tbMonth.Text),
int.Parse(tbDay.Text));
}
catch (FormatException)
|
by: Abelardo Vacca |
last post by:
Hello,
I am currently in the process of switching our application to a N-Tier model
with .NET.
One of the aspects we want ot get right from the start not to worry about it
after is the...
|
by: juergen perlinger |
last post by:
Hello out there.
sometimes I need to have proper control of the floating point arithmetic of
the C(and C++) runtime system, and using the f.p. exception handling of the
C99 standard is quite...
|
by: ChInKPoInt [No MCSD] |
last post by:
I am using Visual Studio 2K3 writing a ASP.NET web application. Is there a
way to force the C# compiler to catch possible exception?
In Java, all exceptions thrown MUST BE caught, otherwise...
|
by: craig |
last post by:
I am wondering if there are some best practices for determining a strategy
for using try/catch blocks within an application.
My current thoughts are:
1. The code the initiates any high-level...
|
by: Chuck Cobb |
last post by:
I'm implementing a centralized exception handling routine using the
Enterprise Library Exception Management Application Block.
I trap all unhandled exceptions to one place using the following...
|
by: Stuart Golodetz |
last post by:
Hi all,
Just wondering whether there's any reason why exception specifications are
enforced at runtime, rather than at compile-time like in Java? (This was
prompted by reading an article on...
|
by: Earl |
last post by:
I have all of my data operations in a separate library, so I'm looking for
what might be termed "best practices" on a return type from those classes.
For example, let's say I send an update from...
|
by: Zorro |
last post by:
The simplicity of stack unraveling of C++ is not without defective
consequences. The following article points to C++ examples showing the
defects. An engineer aware of defects can avoid...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |