Web Connection
Error Handling
Gravatar is a globally recognized avatar based on your email address. Error Handling
  Luca
  All
  Mar 16, 2021 @ 01:34pm

Dear Rick,
I use WC 6.05 and this is the WC error handling in wwProcess:

IF Server.lDebugMode OR ;
   Server.lUseErrorMethodErrorHandling
   
   *** No error handling - let it fail
   this.RouteRequest()
ELSE
   TRY
      THIS.RouteRequest()
   CATCH TO loException
   	  *** Check for re-thrown Exceptions
      IF loException.ErrorNo = 2071 AND ;
         VARTYPE(loException.UserData) = "O" AND ;
         loException.Class = "Exception"
         loException = loException.UserData
      ENDIF

      THIS.OnError(loException)
   ENDTRY
ENDIF

Please how to call also a procedure in MyAppProcess?
I need to check if all the tables are still open and, in case, open them.
For example, something like:

IF Server.lDebugMode OR ;
   Server.lUseErrorMethodErrorHandling
   
   *** No error handling - let it fail
   this.RouteRequest()
ELSE
   TRY
      THIS.RouteRequest()
   CATCH TO loException
   	  *** Check for re-thrown Exceptions
      IF loException.ErrorNo = 2071 AND ;
         VARTYPE(loException.UserData) = "O" AND ;
         loException.Class = "Exception"
         loException = loException.UserData
      ENDIF
      
      MyApplicationProcess.Procedure()
      THIS.OnError(loException)
   ENDTRY
ENDIF

Thank you very much for support

Gravatar is a globally recognized avatar based on your email address. re: Error Handling
  Rick Strahl
  Luca
  Mar 16, 2021 @ 01:56pm

Did you mean to post the same code twice?

Gravatar is a globally recognized avatar based on your email address. re: Error Handling
  Luca
  Rick Strahl
  Mar 16, 2021 @ 02:02pm

No no, the second time I showed the WC error handling plus a call to MyProcess.prg
I tried, but it does not run.
My problem is sometime something close one table (there are many tables open).
Still I had not understand what closes the table but I need to check all the tables to open all of them.
I did think to insert this reaction in error handling, but I do not know how to do.
The application is named Backoffice, your error handling is in wwProcess.prg and I would like to call a procedure into BackofficeProcess.prg

Gravatar is a globally recognized avatar based on your email address. re: Error Handling
  Rick Strahl
  Luca
  Mar 16, 2021 @ 02:08pm

You most definitely should not re-run a request from the error handler as that will only lead to a Stack Overflow (if there's an error after the error). Errors in that handler can be anything so - very, very bad idea.

if a request fails and hits the error handler you need to let it fail. If you need to trap for errors use TRY/CATCH blocks in your own process code and handle any failures there.

+++ Rick ---

Gravatar is a globally recognized avatar based on your email address. re: Error Handling
  Luca
  Rick Strahl
  Mar 16, 2021 @ 10:44pm

Many thanks Rick.
But if I put a TRY/CATCH in my process class, still does run the main WC error handling in wwProcess.prg?

Gravatar is a globally recognized avatar based on your email address. re: Error Handling
  Rick Strahl
  Luca
  Mar 17, 2021 @ 12:46pm

You probably should read up on how error handling in FoxPro works with TRY/CATCH.

  • TRY/CATCH local error handling that you can control
  • Web Connection Error Handling TRY/CATCH at outer execution level

Your TRY/CATCH will capture errors locally - you then have to decide what to do with the error. You can just THROW to rethrow the original error, or do something else like re-run your code as you were trying to do in the code you posted earlier.

Either way - it's never a good idea to re-run code that failed even if you think you 'fixed' the problem. If the error is not fixable or it's actually something different then you end up with a Recursive loop and a Stack over flow.

It's almost always better to fail the request with an error and let the user retry with a clean request.

+++ Rick ---

© 1996-2024