Windows Service

delphi package - automated exception handling

Windows Service

Postby david_navigator » Thu Feb 22, 2018 8:53 pm

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 ?
david_navigator
 
Posts: 3
Joined: Thu Feb 22, 2018 8:45 pm

Re: Windows Service

Postby madshi » Tue Feb 27, 2018 4:37 pm

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
madshi
Site Admin
 
Posts: 9719
Joined: Sun Mar 21, 2004 5:25 pm

Re: Windows Service

Postby david_navigator » Tue Feb 27, 2018 5:54 pm

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
david_navigator
 
Posts: 3
Joined: Thu Feb 22, 2018 8:45 pm

Re: Windows Service

Postby madshi » Tue Feb 27, 2018 7:19 pm

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?
madshi
Site Admin
 
Posts: 9719
Joined: Sun Mar 21, 2004 5:25 pm

Re: Windows Service

Postby david_navigator » Thu Mar 01, 2018 1:10 pm

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:
david_navigator
 
Posts: 3
Joined: Thu Feb 22, 2018 8:45 pm

Re: Windows Service

Postby madshi » Thu Mar 01, 2018 1:14 pm

Haha, glad to hear you got it solved! :)
madshi
Site Admin
 
Posts: 9719
Joined: Sun Mar 21, 2004 5:25 pm


Return to madExcept

Who is online

Users browsing this forum: Baidu [Spider], Exabot [Bot] and 1 guest

cron