cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
] />

Discussions

Solve problems, and share tips and tricks with other JMP users.
Choose Language Hide Translation Bar
hogi
Level XIII

Error message - which line?

JMP helps the user to find errors in the code. If an unresolved  name is used in the code, JMP stops the evaluation and shows an error message - pointing to the erronous line of code

print(1);
result = x + zzz_missing;

hogi_0-1770822119269.png

 

 

Let's make a slight change to the code. When JMP runs this code

myFunc = Function( {x},
	{},
	result = x + zzz_missing;
	Return( result );
);
myFunc( 3 );

it returns again an error message:

hogi_0-1770680122317.png

But it points to line 3 of the code where x is defined. This is very surprising: the error "happens" in line 4 : the user missed a Name expr()  to protect result - and JMP accidentally evaluates the expression!

As we have already discussed this behavior in another post ( Error tracing: JMP tries to "help" ), we will directly move on to the next surprise.

Indeed, even more surprising is the error message for this code:

myFunc = Function( {x},
	{Default Local},
	result = x + zzz_missing;
	Return( result );
);
myFunc( 3 );

hogi_1-1770680211494.png

-> no info about the line !?! - not even a wrong one.

why?

8 REPLIES 8
hogi
Level XIII

Re: Error message - which line?

 Log Capture

according to scripting index, it captures the output to the log and returns it as a string.

hogi_0-1770745977324.png

but it does more than this!

It acts like try() - and allows the execution of the code to continue after a  fatal error inside the evaluated expression.

log=Log capture(
   result = zzz_missing;
   print(1)
);
Print(2);
Show(log)

print(1) is skipped - print(2) is executed.

hogi_2-1770746341174.png

 

almost perfect. Unfortunately (!) it forgets to write the line of code where the error occurs!

hogi
Level XIII

Re: Error message - which line?

Same restriction with Try(): no info about the line of code

Try(
	result = zzz_missing;
	Print( 1 );
,
	Print( exception_msg )
	
);

hogi_3-1770746458783.png

 

hogi
Level XIII

Re: Error message - which line?

Is there a command
- like log Capture() or Try() - which doesn't stop when there is an error in the enclosed expression

- which returns the line of code that produces the error?

hogi
Level XIII

Re: Error message - which line?

Ah: Error Types  by Vince Faller 

hogi_0-1770746969836.png

 

@Ryan_Gilmore , could you please re-activate the wish for voting.

 

 

@Ben_BarrIngh , @russ_wolfinger , fyi.

hogi
Level XIII

Re: Error message - which line?

maybe combine the request with this one:
Improved JSL Stack Trace in Log on Error 

hogi
Level XIII

Re: Error message - which line?

By the way - does anybody know what is returned in the exception message ?

hogi_0-1770747463637.png

1?

2?

hogi
Level XIII

Re: Error message - which line?

Can a JSL code trigger a "child" execution - which might die with an error message about the line of error?
And the main code still survives and is executed further, either when the child execution is finished - or when the child execution is terminated?

hogi
Level XIII

Re: Error message - which line?

// demo command 
MyExpr = Expr(
	Print( 1 );
	z = 5;
	x = xyz;
	Print( 2 );
);




stopnow = 0; // if there is an error, don't execute subsequent blocks of code
summary = "";

// execute blocks of code and collect replies and error messages
For Each( {part, line}, Name Expr( myExpr ), 
	Try(
		Eval( Name Expr( part ) );
		new = "";
	,
		new = "part " || Char( line ) || ":   " || Char( Name Expr( part ) ) || "\!n" || Char( exception_msg );
		stopNow = 1;
	);
	Wait( 0 );
	summary = summary || new || (tmp = Char( Get Log( -1 )[1] ) ; If( tmp == "/*:", "", "\!N" || tmp || "\!N" ));
	Clear Log();
	If( stopnow, break() );
);
Show(summary);

hogi_0-1770757836242.png


Assumes trivial code with  <=1 reply per code block.
Can be easily extended to work with more complicated code.

Recommended Articles