CGI, Handle Exceptions

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

CGI, Handle Exceptions

Marcos Douglas B. Santos
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

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: CGI, Handle Exceptions

Michael Van Canneyt


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.

Michael.
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: CGI, Handle Exceptions

Marcos Douglas B. Santos
On Wed, Jul 20, 2016 at 12:40 PM, Michael Van Canneyt <[hidden email]> 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

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: CGI, Handle Exceptions

leledumbo
Administrator
In reply to this post by Michael Van Canneyt
> 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?
Reply | Threaded
Open this post in threaded view
|

Re: CGI, Handle Exceptions

Marcos Douglas B. Santos
On Wed, Jul 20, 2016 at 10:40 PM, leledumbo <[hidden email]> wrote:
>
> > 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
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal