Windows Service

delphi package - automated exception handling
Post Reply
david_navigator
Posts: 17
Joined: Thu Feb 22, 2018 8:45 pm

Windows Service

Post by david_navigator »

I'm trying to get Madexcept to log exceptions in my service and I'm not getting any results.

I'm configuring the settings thus

Code: Select all

    MESettings.BugReportFile := Get_My_application_data_path + 'Email_service_madexcept.log';
    MESettings.AutoSave := true;
    MESettings.AutoContinue := true;
and in my code I have the following

Code: Select all

                except
                  on E: exception do
                  begin
                    codesite.send('Exception:', E.Message);
                    nxTableIMAPSettings.edit;
                    nxTableIMAPSettings.FieldByName('LastError').asString := formatdatetime('c', now) + ' ' + E.message;
                    nxTableIMAPSettings.post;
                    raise;
                  end;
                end;
The exception gets sent to Codesite (and the table) but I assumed that the raise would allow Madexcept to catch it (and thus give me the call stack).

Any suggestions on what else I need to try ?
madshi
Site Admin
Posts: 10753
Joined: Sun Mar 21, 2004 5:25 pm

Re: Windows Service

Post by madshi »

Is it an interactive or non-interactive service? madExcept is not clever enough to know the difference. So by default madExcept will still try to show an exception dialog. Which will be invisible if the service is not interactive. You will need to configure madExcept to not show the exception dialog. You can do that by changing the bottom right combobox here to "don't show anything":

http://help.madshi.net/madExceptSettings3.htm

Also uncheck the "show please wait box" here:

http://help.madshi.net/madExceptSettings2.htm
david_navigator
Posts: 17
Joined: Thu Feb 22, 2018 8:45 pm

Re: Windows Service

Post by david_navigator »

It's a non-interactive service and the dialogs do match your examples.
Is there somewhere I could insert some codesite messages to work out if the logs simply aren't being written to or whether something is stopping your exception hook from working at all ?

regards

David
madshi
Site Admin
Posts: 10753
Joined: Sun Mar 21, 2004 5:25 pm

Re: Windows Service

Post by madshi »

How do you compile your project? Within the IDE? Or using some automated system (e.g. batch compiling, command line compiling, FinalBuilder etc)?

madExcept does have write access to the log file?

I'm not sure which type of service you're using. Do you use something like TServiceApplication? I don't remember the exact RTL/VCL class name for services. If so, it's possible that there's an TServiceApplication.OnException handler which already catches and handles all exceptions? madExcept only cares about unhandled exception by default. Can you register an OnException handler and inside call madExcept.HandleException()? Maybe that helps?
david_navigator
Posts: 17
Joined: Thu Feb 22, 2018 8:45 pm

Re: Windows Service

Post by david_navigator »

After lots of faffing about, trying this approach and that code etc etc, I suddenly realised that I couldn't see the woods for the trees as there was a try...except around the whole service engine code of mine. Removed that and now working as expected. :oops:
madshi
Site Admin
Posts: 10753
Joined: Sun Mar 21, 2004 5:25 pm

Re: Windows Service

Post by madshi »

Haha, glad to hear you got it solved! :)
Post Reply