Re: Exceptions and WinForms

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Daniel Moth (dmoth74_at_hotmail.com)
Date: 01/18/05


Date: Tue, 18 Jan 2005 12:54:46 -0000

Stepping back and looking at your original question, actually, I'd say that
is expected behaviour. Any exception handling should be done within a form
and not allowed to propagate outside of it (to ShowDialog origin or
otherwise).

So the only thing left to examine is whether there is an incompatibility
with the desktop. Can you try your full framework version of the app built
in Release mode, run from the file system and without VS attached?

Cheers
Daniel

--
http://www.danielmoth.com/Blog/
"JohnNorth" <JohnNorth@discussions.microsoft.com> wrote in message 
news:F553CCA7-DC4A-4D16-98A2-56F8C5A9A01B@microsoft.com...
> Hi Daniel.
> No, this happens with and without the debugger.
> The full framework works correctly.
>
> "Daniel Moth" wrote:
>
>> Does this happen only when you are debugging? In other words, try the 
>> same
>> app that exhibits the problem by manually launching it on the device 
>> without
>> VS attached and see if the dialog stays up with no secondary exception.
>>
>> Cheers
>> Daniel
>> --
>> http://www.danielmoth.com/Blog/
>>
>>
>> "JohnNorth" <JohnNorth@discussions.microsoft.com> wrote in message
>> news:EC0D3186-D07F-4F52-9894-4B6271DED15C@microsoft.com...
>> > Hi Daniel.
>> > Thanks for replying.
>> >
>> > Below is some example code.
>> >
>> > private void Form1_KeyPress(object sender,
>> > System.Windows.Forms.KeyPressEventArgs e)
>> > {
>> >
>> > Form2 frm2;
>> >
>> > if(e.KeyChar == 'A' || e.KeyChar =='a' )
>> > {
>> > frm2 = new Form2();
>> >
>> > try
>> > {
>> > frm2.ShowDialog();
>> > }
>> > catch(Exception)
>> > {
>> > //MessageBox.Show("Form2 through exception" + Ex.Message);
>> > }
>> > finally
>> > {
>> > frm2.Dispose();
>> > frm2=null;
>> >
>> > }
>> >
>> >
>> > frm2 = new Form2();
>> >
>> > try
>> > {
>> > frm2.ShowDialog();
>> > }
>> > finally
>> > {
>> > frm2.Dispose();
>> > frm2 = null;
>> > }
>> > }
>> >
>> > Form2 Key presss event
>> >
>> > private void Form2_KeyPress(object sender,
>> > System.Windows.Forms.KeyPressEventArgs e)
>> > {
>> > if (e.KeyChar == 'A' || e.KeyChar =='a')
>> > throw new Exception("From2 exception");
>> >
>> > }
>> >
>> >
>> > "Daniel Moth" wrote:
>> >
>> >> Do you recreate the form before calling ShowDialog again? Show some 
>> >> code
>> >>
>> >> Cheers
>> >> Daniel
>> >> --
>> >> http://www.danielmoth.com/Blog/
>> >>
>> >>
>> >> "JohnNorth" <JohnNorth@discussions.microsoft.com> wrote in message
>> >> news:5EB2DE6C-F32D-4C97-9B7B-6CAE8F33CB3F@microsoft.com...
>> >> > It appears that exception handling outside of a form corrupts 
>> >> > winforms.
>> >> >
>> >> > If we have two forms say form1 and form2. On form1 (our start form)
>> >> > I've
>> >> > put
>> >> > a button click event which does a showdialog() for form2. In this 
>> >> > click
>> >> > event
>> >> > I've got a try catch around the showdialog method. On form2 I've 
>> >> > added
>> >> > a
>> >> > button and a click event which deliberately throws an exception. 
>> >> > When
>> >> > the
>> >> > exception is thrown in form2 the code correctly arrives back at the
>> >> > catch
>> >> > in
>> >> > form1. Any subsequent calls to showdialog() then fails with no
>> >> > exceptions
>> >> > thrown.
>> >> >
>> >> > Any Ideas
>> >>
>> >>
>> >>
>>
>> 


Relevant Pages

  • Re: Error handling
    ... Daniel, it's a bit difficult to paste my code as it's pretty long. ... My form calls a static method in Class2 ... > you might as well not catch the exception and let it bubble up. ...
    (microsoft.public.dotnet.framework.compactframework)
  • Re: Compact framework and web services
    ... > Thanks Daniel ... > I have tried your suggestion but it seems to make no difference. ... > I cant understand why I am getting a native exception. ... >> There may not be too much in the way of calling web services through SSL ...
    (microsoft.public.dotnet.framework.compactframework)
  • Re: Exceptions and WinForms
    ... if you are trying to literally handle an exception (i.e. ... If you look at the help for each method of the framework ... GEH is there for bugs (you should have handled it but you didn't so while ... > Hi Daniel. ...
    (microsoft.public.dotnet.framework.compactframework)
  • Re: Exceptions and WinForms
    ... you should trap exceptions (of the specific types in ... On the full framework you can also apply global exception handling but again ... > Hi Daniel. ...
    (microsoft.public.dotnet.framework.compactframework)
  • Re: ObjectDisposed exception
    ... > Hello Daniel, ... > Public Sub Exit_Main ... Where are you getting the exception, ... >>> I develop a simple smart device application and sometimes when i exit ...
    (microsoft.public.dotnet.framework.compactframework)