The following example works for me. This will attach a method to the firstchangeexception event and then will raise an exception to see it execute. The handler will write the exception to the event log. Because an event log should not be used immediately after it is created the example should be run twice.
You should also protect the static method using a mutex or the sync statement if this is a multi-threaded application.
$set ilusing"System.Runtime.ExceptionServices" $set ilusing"System.Diagnostics" $set ilusing"System.Threading" class-id testfirstexception.Class1. working-storage section. method-id main static. local-storage section. procedure division. attach method ExceptHandler to type AppDomain::CurrentDomain::FirstChanceException try raise new ArgumentException("Thrown in " & type AppDomain::CurrentDomain::FriendlyName) catch ex as type ArgumentException display "ArgumentException caught in " & type AppDomain::CurrentDomain::FriendlyName & " " & ex::Message end-try goback. end method. method-id ExceptHandler public static. procedure division using by value s as object, e as type FirstChanceExceptionEventArgs. *> Create the source, if it does not already exist. if not type EventLog::SourceExists("MySource") *>An event log source should not be created and immediately used. *>There is a latency time to enable the source, it should be created *>prior to executing the application that uses the source. *>Execute this sample a second time to use the new source. invoke type EventLog::CreateEventSource("MySource", "MyNewLog") display "CreatedEventSource" display "Exiting, execute the application a second time to use the source." *> The source is created. Exit the application to allow it to be registered. goback else *> Create an EventLog instance and assign its source. declare myLog as type EventLog = new EventLog set myLog::Source to "MySource" *> Write an informational entry to the event log. invoke myLog::WriteEntry("FirstChanceException event raised in " & type AppDomain::CurrentDomain::FriendlyName & " " & e::Exception::StackTrace) end-if goback. end method. end class.