cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Choose Language Hide Translation Bar
mat-ski
Level III

Is there a way to capture logs without silencing exceptions?

In my test framework I would like to cut out the clutter that results from Prints/Writes/handled exceptions from my output file, so I tried executing test code inside of a Log Capture( Eval( testExpression ) ). My problem is that this seems to also silence any exceptions that get thrown when evaluating the testExpression, which I did not expect.

 

As an example:

Try(
	logs = Log Capture( 
		Throw( "newsflash buddy!" );
	);
Print( "Logs: " || logs ); , Print( "Error:" || exception_msg ) );


I would like to get the logs, but still end up in the catch in case the code inside of the Capture throws.

 

Side-question: my thrown exception doesn't actually appear in the logs, which further confuses me as to why the capture silences it.

1 ACCEPTED SOLUTION

Accepted Solutions
Craige_Hales
Super User

Re: Is there a way to capture logs without silencing exceptions?

I don't remember the details, but it was necessary for LogCapture to handle any unresolved throws. It can't rethrow and save the result into logs without your help--something like this:

Try(
	logs = Log Capture(
		Try(
			rememberException = Empty();
			Print( "Hello" );
			Throw( "newsflash buddy!" );
		,
			rememberException = exception_msg
		)
	);
	Print( "Logs: " || logs );
	If( !Is Empty( rememberException ),
		throw( "remember: " || rememberException )
	);
,
	Print( "Error: " || exception_msg )
);

"Logs:
\!"Hello\!""
"Error: remember: newsflash buddy!"

Craige

View solution in original post

5 REPLIES 5

Re: Is there a way to capture logs without silencing exceptions?

See if this function works for your purpose.

log.PNG

mat-ski
Level III

Re: Is there a way to capture logs without silencing exceptions?

Hi Mark, the function that you've linked is the one to which I was referring in my original post. The issue that I am having is that exceptions thrown in the expressions inside the capture are suppressed. For instance, in my snippet above, the Print in the catch block does not get executed.

Re: Is there a way to capture logs without silencing exceptions?

I forgot to mention that you can save the result returned by this function for examination. @Craige_Hales' reply shows how you might use this function instead of printing from within any code provided as an argument. I'm sorry for the confusion.

Craige_Hales
Super User

Re: Is there a way to capture logs without silencing exceptions?

I don't remember the details, but it was necessary for LogCapture to handle any unresolved throws. It can't rethrow and save the result into logs without your help--something like this:

Try(
	logs = Log Capture(
		Try(
			rememberException = Empty();
			Print( "Hello" );
			Throw( "newsflash buddy!" );
		,
			rememberException = exception_msg
		)
	);
	Print( "Logs: " || logs );
	If( !Is Empty( rememberException ),
		throw( "remember: " || rememberException )
	);
,
	Print( "Error: " || exception_msg )
);

"Logs:
\!"Hello\!""
"Error: remember: newsflash buddy!"

Craige
mat-ski
Level III

Re: Is there a way to capture logs without silencing exceptions?

Thanks Craige, this is perfect!