Global Exception handler in Module

M

Masa Ito

I am trying to follow the great advice that seems to be said over and over
by good people (like Jay Harlow) about putting a global exception handler
in Sub Main.

Our app has Sub Main in a module. I can add the handler and then can add
the sub, but I can't add it as a shared sub inside this module - V.S. tells
me shared subs are not allowed. Is there another way I can do this while
maintaining this module?
Public Module AppStart
Public Sub Main()
AddHandler Application.ThreadException, AddressOf
OnThreadException
...
End Sub

Private Shared Sub OnThreadException(ByVal sender As Object, ByVal e
as System.Threading.ThreadExceptionEventArgs)
' log e.Exception here
End Sub
End Module

Thanks,
Masa
 
H

Herfried K. Wagner [MVP]

Masa Ito said:
Our app has Sub Main in a module. I can add the handler and then can add
the sub, but I can't add it as a shared sub inside this module - V.S.
tells
me shared subs are not allowed. Is there another way I can do this while
maintaining this module?
Public Module AppStart
Public Sub Main()
AddHandler Application.ThreadException, AddressOf
OnThreadException
...
End Sub

Private Shared Sub OnThreadException(ByVal sender As Object, ByVal e

Simply remove the 'Shared' keyword.
 
G

Guest

As Herfried said, drop the "Shared".
That's because modules are really just a shorthand for NotInheritable,
non-instantiatable classes with only Shared members - since the members are
already Shared, you can't add it explicitly.
--
David Anton
www.tangiblesoftwaresolutions.com
Instant C#: VB.NET to C# Converter
Instant VB: C# to VB.NET Converter
Instant C++: C# to C++ Converter
Instant J#: VB.NET to J# Converter
 
M

Masa Ito

As Herfried said, drop the "Shared".
That's because modules are really just a shorthand for NotInheritable,
non-instantiatable classes with only Shared members - since the
members are already Shared, you can't add it explicitly.

<redfaced>
Thanks!
Got the global exception handler working - but it isn't serializing the
good stuff from the exception (app uses remoting). Off to bang my head
against a new wall now. :)

Masa
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top