Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2016-07

CGI, Handle Exceptions

5 messages · 3 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Marcos Douglas

Hi,

Is possible to get all exceptions in one place, in a CGI/FastCGI programs?

I need to know the Request instance too, to treat the exception properly.

Regards,
Marcos Douglas

Michael Van Canneyt
to Marcos Douglas
Marcos Douglas wrote 5 lines
Hi, Is possible to get all exceptions in one place, in a CGI/FastCGI programs? I need to know the Request instance too, to treat the exception properly.

No, you cannot.

You can override Application.ShowException, but then you do not know the current request.

What I do is make a descendent of TFPWebModule which overrides "HandleRequest', and which handles exceptions in a generic way. It returns JSON when the request expects JSON etc.

All my other modules are descendent of this descendent.

Michael.

Marcos Douglas
to Michael Van Canneyt

On Wed, Jul 20, 2016 at 12:40 PM, Michael Van Canneyt <

Show quoted text 24 lines
wrote: On Wed, 20 Jul 2016, Marcos Douglas wrote: Hi, > > Is possible to get all exceptions in one place, in a CGI/FastCGI programs? > > I need to know the Request instance too, to treat the exception properly. > No, you cannot. You can override Application.ShowException, but then you do not know the current request. What I do is make a descendent of TFPWebModule which overrides "HandleRequest', and which handles exceptions in a generic way. It returns JSON when the request expects JSON etc. All my other modules are descendent of this descendent.

Hmm, could be a solution. Thank you.

Marcos Douglas

leledumbo
to Michael Van Canneyt: No, you cannot. You can override Application.ShowException, but then you do not know the…
I need to know the Request instance too, to treat the exception properly.

As Michael has pointed out, the current design has no access to the TRequest instance. My alternative solution would be to create descendant Exception class that has Request property. For every exception you raise deliberately, use this class. But you know this is limited to such an exception only...

You can override Application.ShowException, but then you do not know the current request.

What was the idea behind OnShowRequestException only gets TResponse instead of along with TRequest?

View this message in context: http://free-pascal-general.1045716.n5.nabble.com/CGI-Handle-Exceptions-tp5725746p5725749.html Sent from the Free Pascal - General mailing list .
Marcos Douglas
to leledumbo
leledumbo wrote 7 lines
> I need to know the Request instance too, to treat the exception properly. As Michael has pointed out, the current design has no access to the TRequest instance. My alternative solution would be to create descendant Exception class that has Request property. For every exception you raise deliberately, use this class. But you know this is limited to such an exception only...

But some exceptions I don't have control (exceptions, of course). I will always need the context to any exception. So, Michael tip is simple to implement to have full control of exceptions.

Regards,
Marcos Douglas