AddHandler syntax error

I have the following lines of code in my app (I put them in a module for global use)...I am getting a syntax error on the AddHandler (only that word is underlined), but when I look at the documentation, the syntax looks the same (see copied code below mine)

    'The 2 event handlers
    'add an unhandled exceptions handler
    Public currentDomain As AppDomain = AppDomain.CurrentDomain
    'for regular unhandled stuff
AddHandler currentDomain.UnhandledException, AddressOf Me.MYExceptionHandler
    'for threads behind forms
AddHandler Application.ThreadException, AddressOf Me.MYThreadHandler

    Private Sub MYExceptionHandler(ByVal sender As Object, ByVal e As UnhandledExceptionEventArgs)
          MsgBox("Handled Error") ' Just put tha there for the question

    End Sub

    Private Sub UHThreadEX(ByVal sender As Object, ByVal e As Threading.ThreadExceptionEventArgs)

           MsgBox("Unhandled Error") ' Just put tha there for the question

    End Sub

MS Code:

AddHandler MyObject.Event1, AddressOf Me.MyEventHandler
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

You can't use the keyword Me within a Module.

   AddHandler currentDomain.UnhandledException, AddressOf MYExceptionHandler
   AddHandler currentDomain.UnhandledException, AddressOf MyModuleName.MYExceptionHandler

You might also need to make your handler subs Public instead of Private (that is sometimes, but not always, necessary).
BodeTechAuthor Commented:
I got the correct answer in a MS forum.  Addhandlers have to be in a Sub or Function.  Once I moved it, I was fine.
PAQd, 500 points refunded - asker posted their solution

Community Support Moderator

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.