Link to home
Start Free TrialLog in
Avatar of TSFLLC
TSFLLC

asked on

How can I release an Unhandled ErrorHandler

I am attempting to pass the value of a variable called glInitials from my main program to my UnhandledErrorHandler function in a linked Class Library to be included in file naming for an attachment that will be sent to my developers.  We have no problem passing glInitials but until a user completes my login form glInitials is set to nothing.

I want to continue loading my UnhandledErrorHandler on startup but I also want to be able to "re-initialize" the same Handler with updated glInitials after the login.

Can I simply create a new entry upon login as I do on startup or do I need to release (if I can) the ErrorHandler and then initialize it again ??

Please help.  Thanks in advance.
Phil Tate
Avatar of Nasir Razzaq
Nasir Razzaq
Flag of United Kingdom of Great Britain and Northern Ireland image

This description does not make any sense to me. Is the unhandlederrorhandler another class? Is it written by you?
Yeah, I agree that question makes no sense, but I am curious to find out what it means...
Avatar of TSFLLC
TSFLLC

ASKER

Yes, the unhandlederrorhandler is IN another class.  I have both an unhandled and handled errorhandler in a separate class library.

I'm initially loading the unhandlederrorhandler on startup of my project, passing my initials (PT) to the errorhandler.  But when the user logs in, I want to re-initialize the errorhandler with their initials.  I use the intials in the creation of a .png that is included as an attachment (ex. - PT_Unhandled24155.png).

Because I didn't get any postings yesterday I went ahead and just set UnhandledErrorManager.AddHandler("PT") on startup and then after logging in I re-enter the line UnhandledErrorManager.AddHandler(trim(glInitials)).  In testing I found that if I did not enter the 2nd entry of the handler that the passing of glInitials remained "PT".

I hope that makes sense now.  Again, will I have a problem with setting the handler twice? Or should I do something different?

Thanks guys.
SOLUTION
Avatar of Bob Learned
Bob Learned
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of TSFLLC

ASKER

That's what I do not know how to do.  How can I 'remove/release/dispose' of the first event handler?
The reverse for AddHandler is RemoveHandler.
Avatar of TSFLLC

ASKER

Please excuse my ignorance.  This is new territory for me.  Because of that I think I was too close to it to see the reverse.   :)

I didn't write this errorhandler and it does not have a RemoveHandler in it.  I've been searching for a custom RemoveHandler....with no luck.  I also see that you can use, although I don't know if appropriate in this situation.....   RemoveHandler Object As Event, Object As Delegate when I highlight the word RemoveHandler.  However I'm not associating it with an event.  Am I?

What can I do?

Sincerely!
Phil Tate
Avatar of TSFLLC

ASKER

Is it as simple as adding the additional Public Shared Sub [RemoveHandler] into the UnhandledException class below?
    Public Shared Sub [AddHandler](ByVal xString As String)
        '-- get value of glInitials from main program for use with file names and system.random
        _UserInitials = Trim(xString)
        '-- attempt to load optional settings from .config file
        LoadConfigSettings()
 
        '-- track the parent assembly that set up error handling
        '-- need to call this NOW so we set it appropriately; otherwise
        '-- we may get the wrong assembly at exception time!
        ParentAssembly()
 
        '-- for winforms applications
        RemoveHandler Application.ThreadException, AddressOf ThreadExceptionHandler
        AddHandler Application.ThreadException, AddressOf ThreadExceptionHandler
 
    End Sub
 
    Public Shared Sub [RemoveHandler]()
        '-- for winforms applications
        RemoveHandler Application.ThreadException, AddressOf ThreadExceptionHandler
 
    End Sub

Open in new window

ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of TSFLLC

ASKER

Nasir,

I wish I had greater experience with this.  You are so right.  As I was adding RemoveHandler I was looking at the AddHandler code and it did not even dawn on me that it is performing cleanup within itself.

Perfect.

Thanks to both of you.  I couldn't do without EE.