Subscribe for automatic updates: RSS icon RSS

Login icon Sign in for full access | Help icon Help
Advanced search

Pages: [1]
  Reply  |  Print  
Author Topic: TRY/END TRY  (Read 10972 times)
Tim B.
Posts: 67


« on: March 25, 2011, 10:36:42 am »

We have made extensive use of this in our project, but the side effect is that error messages are not suppressed and still go to the log.  We could redirect these in every statement with STARTLOG, but it's not really ideal. 

Is there any other way of doing it, or could something like a profile directive be added in the future?
Reuben B.
Four Js
Posts: 1119


« Reply #1 on: March 29, 2011, 12:18:06 am »

To avoid messages going to the ERRORLOG, use WHENEVER ANY ERROR CONTINUE https://4js.com/online_documentation/fjs-fgl-manual-html/User/Exceptions.html#TRACE, unfortunately that doesn't help you as TRY is effectively a WHENEVER ANY ERROR GOTO https://4js.com/online_documentation/fjs-fgl-manual-html/User/Exceptions.html#TRYCATCH

I'm guessing you are using TRY so that ...

Code
  1.   TRY
  2.      LET x =  1/0
  3.   CATCH
  4.      CASE STATUS
  5.         WHEN -1202 DISPLAY "Divide by zero error"
  6.         OTHERWISE CALL ERRORLOG("Some other error")
  7.      END CASE
  8.   END TRY

... is the equivalent of ...

Code
  1.   WHENEVER ANY ERROR CONTINUE
  2.   LET x =  1/0
  3.   CASE STATUS
  4.      WHEN -1202 DISPLAY "Divide by zero error"
  5.      OTHERWISE CALL ERRORLOG("Some other error")
  6.   END CASE
  7.   WHENEVER ANY ERROR STOP

... and as you've discovered, the TRY will write messages to the ERRORLOG whilst WHENEVER ANY ERROR CONTINUE doesn't.

Personally I'd like to see CATCH be able to trap certain exceptions ...

Code
  1. WHENEVER ANY ERROR CALL error_handler
  2. TRY
  3.   LET x = 1/0
  4. CATCH -1202
  5.   DISPLAY "Divide by zero error"
  6. END TRY

... so that I can handle the error I have anticipated, and let the normal error handler deal with unexpected errors.  Certainly in that case I wouldn't want the error I have anticipated and dealt with to appear in the errorlog, but I would want the unanticipated error to be in the errorlog.

For now, you could get clever with the pre-processor and do something like ...

Code
  1. &define TRY_NOLOG CALL STARTLOG("/dev/null") TRY
  2. &define END_TRY_NOLOG END TRY CALL STARTLOG("error.log")
  3.  
  4.  TRY_NOLOG
  5.     LET x =  1/0
  6.  CATCH
  7.     CASE STATUS
  8.        WHEN -1202 DISPLAY "Divide by zero error"
  9.     END CASE
  10.  END_TRY_NOLOG

Reuben

Product Consultant (Asia Pacific)
Developer Relations Manager (Worldwide)
Author of https://4js.com/ask-reuben
Contributor to https://github.com/FourjsGenero
Sebastien F.
Four Js
Posts: 545


« Reply #2 on: March 29, 2011, 10:28:30 am »

Hello,

I would avoid to use the preprocessor until there is no other way to solve a blocking problem or missing language instruction.

So I would not use preprocessor macros for this issue, having additional records in the log is not that critical.
You get the line number in the source so you know if comes from a TRY/CATCH block and can be ignored.
But I agree it can be annoying.

I will talk with the team to see what we can do.

Seb
Tim B.
Posts: 67


« Reply #3 on: March 29, 2011, 05:01:52 pm »

Thanks for the responses.   The errors in the log are not critical, but we keep a close eye on them, and there are now so many errors it's difficult to find the real ones amongst all the rest.

We're using TRY for a number of different things, but mostly to check that DELETEs are either successful, or fail due to referencial integrity issues (which saves a lot of checking).

Being able to catch specific exceptions which you are expecting (and avoid the error logging) would be a very good enhancement.
Tim B.
Posts: 67


« Reply #4 on: July 12, 2011, 11:57:08 am »

Has there been an further thoughts on this one al all?
Sebastien F.
Four Js
Posts: 545


« Reply #5 on: July 12, 2011, 12:40:57 pm »

Hello,
The topic is registered in our bug database with id #20606
Seb
Pages: [1]
  Reply  |  Print  
 
Jump to:  

Powered by SMF 1.1.21 | SMF © 2015, Simple Machines