Question
Norman W. Freeman · May 26

How to add a try / catch block inside a routine that contains indentation with "." characters ?

I have some code in a mac routine that use indentation and the "." character : 
 

 IF condition1 DO
     .WRITE YCR,...
     .WRITE YCR,...
     .WRITE YCR,...

I would like to add a try / catch block between the write statements.
I can't refactor the whole code and use indentation with curly braces instead (there is too much code, not written by me)

I have tried the following but it does not work (it compiles, but code stop running right before the try keyword)

 IF condition1 DO
    try {
        .WRITE YCR,...
        .WRITE YCR,...
        .WRITE YCR,...
    }
    catch {
    }

Is this something supported ? If yes, what is the syntax to use?

It seems to be OK if I include the if inside the try catch :

try {
     IF condition1 DO
        .WRITE YCR,...
        .WRITE YCR,...
        .WRITE YCR,...
 }
 catch {
 } 
Product version: Caché 2018.1
00
1 0 2 92
Log in or sign up to continue

You'll have to put the Try-Catch construct at the same dot-level:

If 1 Do
. Try {
. Write a=b
. } Catch e {
. ZWrite e
. }

Thanks, it works. I already tried something similar but put the the "}" and the "catch {" on separate lines. The trick is to put them on the same line.