exception on form.show (vb.Net windows forms) 
Author Message
 exception on form.show (vb.Net windows forms)

Hi,

I have a problem where an exception thrown by the form
Load event is causing an unhandled exception, even though
the code calling the form has exception handling.

The wierdest thing is that is only happens in the released
runtime, and not when I am running the development
environment in debug mode.

We were originally using our own exception class,
inheriting System.ApplicationException, but I have also
tried throwing a standard System.Exception with the same
result.

The unhandled exception is not very specific and occurs
when the exception is thrown, but before the thrown
exception reaches the calling code.  The unhandled
exception is then caught by the exception handling in
Function ShowForm (code shown at end of posting).

Can anyone help?

Cheers,
Chris

************** Exception Text **************
System.Exception: Already locked
   at Forms.frmCOLLEGE_SM.Lock() in C:\Tekra
LMS\Forms\College\frmCOLLEGE_SM.vb:line 499
   at Forms.frmCOLLEGE_SM.Form_Retrieve() in C:\Tekra
LMS\Forms\College\frmCOLLEGE_SM.vb:line 392
   at Forms.frmCOLLEGE_SM.Form_Load(Object sender,
EventArgs e) in C:\Tekra
LMS\Forms\College\frmCOLLEGE_SM.vb:line 365
   at System.Windows.Forms.Form.OnLoad(EventArgs e)
   at System.Windows.Forms.Form.OnCreateControl()
   at System.Windows.Forms.Control.CreateControl(Boolean
fIgnoreVisible)
   at System.Windows.Forms.Control.CreateControl()
   at System.Windows.Forms.Control.WmShowWindow(Message& m)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.ScrollableControl.WndProc
(Message& m)
   at System.Windows.Forms.ContainerControl.WndProc
(Message& m)
   at System.Windows.Forms.Form.WmShowWindow(Message& m)
   at System.Windows.Forms.Form.WndProc(Message& m)
   at System.Windows.Forms.ControlNativeWindow.OnMessage
(Message& m)
   at System.Windows.Forms.ControlNativeWindow.WndProc
(Message& m)
   at System.Windows.Forms.NativeWindow.Callback(IntPtr
hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

******************* Calling Code ***********************
Private Function ShowForm(ByRef MDIParent As
System.Windows.Forms.Form, ByRef OpeningForm As Object,
ByRef formModality As Forms.Modality) As Boolean
        Try
                With OpeningForm
                        .MdiParent = MDIParent
                        .Modality = formModality
                        .Show()
                        .Activate()
                        .Enabled = True
                End With
        Catch ale As ADF.Global.PAlreadyLockedException
                OpeningForm.dispose()
                Return False
        Catch fcble As FormCannotBeLoadedException
                PLogFile.Log(fcble.ToString)
                PMessageBox.ShowError("There was a problem
activating this form (" & OpeningForm.name & "). See Log
File for Details.")
                Return False
        Catch ex As Exception
                If TypeOf ex.InnerException Is
ADF.Global.PAlreadyLockedException Then
                        OpeningForm.dispose()
                End If
                If TypeOf ex.InnerException Is
ADF.Global.FormCannotBeLoadedException Then
                        PLogFile.Log
(ex.InnerException.ToString)
                        PMessageBox.ShowError("There was a
problem activating this form (" & OpeningForm.name & ").
See Log File for Details.")
                End If
                Return False
        End Try
        Return True
End Function



Sat, 24 Sep 2005 16:28:17 GMT  
 exception on form.show (vb.Net windows forms)
--------------------
| Content-Class: urn:content-classes:message

| Subject: exception on form.show (vb.Net windows forms)
| Date: Tue, 8 Apr 2003 01:28:17 -0700
|
| I have a problem where an exception thrown by the form
| Load event is causing an unhandled exception, even though
| the code calling the form has exception handling.
|
| The wierdest thing is that is only happens in the released
| runtime, and not when I am running the development
| environment in debug mode.
|
| We were originally using our own exception class,
| inheriting System.ApplicationException, but I have also
| tried throwing a standard System.Exception with the same
| result.
|
| The unhandled exception is not very specific and occurs
| when the exception is thrown, but before the thrown
| exception reaches the calling code.  The unhandled
| exception is then caught by the exception handling in
| Function ShowForm (code shown at end of posting).

[code snipped]

Two things appear to me right away:

1) I don't see ShowForm anywhere in the callstack you gave with the
exception. This could mean that you're not reaching the try/catch block
that you pasted. When the exception hits, try browsing through the
Callstack window to see if you can be certain that it's passing through the
code you gave.

2) "Already locked" sounds like a concurrency issue to me. If your program
is threaded, and the exception is being thrown in a different thread than
the catcher, you're not going to catch it, even if the new thread is
created inside a try/catch block.

- Matt
MS VB QA



Mon, 26 Sep 2005 04:16:06 GMT  
 exception on form.show (vb.Net windows forms)
Thanks for getting back to me Matt.

1) The exception is thrown by our own code that is called
during the FormLoad event which is why I think ShowForm is
not listed.  During FormLoad, we check to see if the
record the user is retrieving is being used by another
user, and if it is we throw an exception back.  We want to
capture this "Already Locked (by another user)" exception
and throw a specific exception back to the calling form to
handle disposing of the form so that the user cannot open
the form.
Is there a problem with throwing an exception back during
FormLoad?  And should we be running this sort of code in
the form's constructor instead?

2) The "Already Locked" message is misleading you.  This
is our own message with is thrown with the exception and
we are not using different threads.

cheers,
Chris

Quote:
>-----Original Message-----
>--------------------
>| Content-Class: urn:content-classes:message

>| Subject: exception on form.show (vb.Net windows forms)
>| Date: Tue, 8 Apr 2003 01:28:17 -0700
>|
>| I have a problem where an exception thrown by the form
>| Load event is causing an unhandled exception, even
though
>| the code calling the form has exception handling.
>|
>| The wierdest thing is that is only happens in the
released
>| runtime, and not when I am running the development
>| environment in debug mode.
>|
>| We were originally using our own exception class,
>| inheriting System.ApplicationException, but I have also
>| tried throwing a standard System.Exception with the
same
>| result.
>|
>| The unhandled exception is not very specific and occurs
>| when the exception is thrown, but before the thrown
>| exception reaches the calling code.  The unhandled
>| exception is then caught by the exception handling in
>| Function ShowForm (code shown at end of posting).

>[code snipped]

>Two things appear to me right away:

>1) I don't see ShowForm anywhere in the callstack you
gave with the
>exception. This could mean that you're not reaching the
try/catch block
>that you pasted. When the exception hits, try browsing
through the
>Callstack window to see if you can be certain that it's

passing through the
Quote:
>code you gave.

>2) "Already locked" sounds like a concurrency issue to

me. If your program
Quote:
>is threaded, and the exception is being thrown in a

different thread than

- Show quoted text -

Quote:
>the catcher, you're not going to catch it, even if the
new thread is
>created inside a try/catch block.

>- Matt
>MS VB QA

>.



Mon, 26 Sep 2005 17:19:14 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Unhandled exception in system.windows.forms.dll (in my main form) - argh

2. VB.NET - Subclassing System.Windows.Forms.Form?

3. tabbing problems when showing .net form form vb6

4. Open form, close form, open form = disposed object exception

5. Deploying vb.net windows form application on a pc without the .net framework

6. How to Show the form again after run another form on Windows 3.11

7. Form.show command in VB.NET

8. loading/showing forms in vb.net

9. how to show a form in vb.net

10. vb.net showing a form after hiding it

11. form.show (VB6) = ???(VB.NET)

12. show/hide form in vb.net

 

 
Powered by phpBB® Forum Software