Error Handling in Declarations Section

  • Thread starter Thread starter Workaholic
  • Start date Start date
W

Workaholic

Hi,
I have written an application in which I am using a third party
control. I have declared the control using a DIM statement in the
Declarations Section of the application, so that it is available to
all functions and sub-routines in the application. Everything works
fine on my development PC.

If I install the application onto a second PC, which does not have the
third party control installed, then I get problems (which you'd
expect!). The application dies immediately with a "Application has
generated an exception that could not be handled" messagebox.

Please can somebody tell me how I can handle this error. I can handle
errors in functions and sub-routines, but I don't know how to handle
an error that is coming from the declarations section!

Thanks
 
my guess is that your declaration is something like:
dim x as new y

change it to dim x as y
and in your classes Sub New()
add a try catch to instanciate it
Try
x = new y
etc.

You can also add an UnhandeledEvent handeler to your application level events.
 
Hi,
I have written an application in which I am using a third party
control. I have declared the control using a DIM statement in the
Declarations Section of the application, so that it is available to
all functions and sub-routines in the application. Everything works
fine on my development PC.

If I install the application onto a second PC, which does not have the
third party control installed, then I get problems (which you'd
expect!). The application dies immediately with a "Application has
generated an exception that could not be handled" messagebox.

Please can somebody tell me how I can handle this error. I can handle
errors in functions and sub-routines, but I don't know how to handle
an error that is coming from the declarations section!

Thanks

If i understood correctly, you do not need to handle the exception in
declaration area (Dim x As New xxx....). Just handle it when you call
this library's one of functions using Try-Catch Block.

I mean;

(Untested)

Public Class Form1

Dim control As New <your_control>

Public Sub <Function>(........)

Try

' Code to be done

Catch

'...Msgbox is good
Msgbox("Error",.....)

Finally

' ...Optional

End Try

End Sub

The code sample is demo, modify and correct as you wish if you need.
Handle exception when you call a function of your library, but this
not a solution, i'd install the library on target machine not to have
an exception though.
 
Workaholic said:
I have written an application in which I am using a third party
control. I have declared the control using a DIM statement in the
Declarations Section of the application, so that it is available to
all functions and sub-routines in the application. Everything works
fine on my development PC.

If I install the application onto a second PC, which does not have the
third party control installed, then I get problems (which you'd
expect!). The application dies immediately with a "Application has
generated an exception that could not be handled" messagebox.

VB Application Model:
'My.Application.UnhandledException'.

Windows Forms:
'System.Windows.Forms.Application.ThreadException'.

[
Console applications:
'System.AppDomain.UnhandledException'.

ASP.NET:
'System.Web.HttpApplication.Error' event in "Global.asax".
]
 
Thanks to everyone for their input. Terry's suggestion of making the
declaration (DIM) in the declarations section but then assigning it
within a function (within a TRY block) worked perfectly. Many thanks
 
Back
Top