Subscribe Bookmark RSS Feed

how to bypass parse("a+b)") error?

wma1125

Community Trekker

Joined:

May 9, 2012

how to by pass parse("a+b)")  error? I've tried Try() but it didn't work..

4 REPLIES
txnelson

Super User

Joined:

Jun 22, 2012

Parsing the string "a+b)" will result in an error because of unbalanced parentheses.  Can you provide more context on what you are attempting to do?

Jim
Craige_Hales

Staff

Joined:

Mar 21, 2013

try this to keep the unwanted message out of the log:

exp = 0;

cap = 0;

cap = Log Capture( // capture anything written to log

  exp = Try( //

  Parse( "a+b)" ); //parse will throw AND write to log

  ,

  42; // if the jsl fails to parse

  )

);

Show( exp, cap ); // show what happened

exp = 42;

cap = " <<< this is the captured error message, you don't have to print it

Unexpected \!")\!". Perhaps there is a missing \!";\!" or \!",\!".

Line 1 Column 4: a+b►)

The remaining text that was ignored was

)";


It took me a couple of tries to get this right; the LogCapture must be outside of the try to get the results I think you want.  Setting cap and exp to zero is not required, that was part of my debugging my JSL.  They will both be set by the try and logCapture. 


There are some other JSL functions with this behavior, and LogCapture will work for them too.

Craige
msharp

Super User

Joined:

Jul 28, 2015

Thanks for this tip, this sure will help keeping the log file clean.

wma1125

Community Trekker

Joined:

May 9, 2012

thanks, Graige. I was trying to parse some formula from an excel table where users key in their formula. However, sometimes there are typos..