Ask a Question

how to debug Exception during file read/write

mateenhussain
Occasional Contributor

how to debug Exception during file read/write

Hi



I'm having problem while trying to create a log file using the command




Log.SaveResultsAs(path+fileName+".mht",2)



Where path & fileName are dynamically generated. And I do understand if there's no Path (on the computer), TC/TE creates one. So the above piece of code used to work fine for me, over the past two months, but all of a sudden I dont see any log file being created, coz the above command returns a boolean false.



The problem now is, I dont know what is causing the above function to return a False value, when the same thing was working earlier. If the code would have been returning an exception it would have been easy for me to debug what was causing the problem. How do I make the code to throw an exception with what is causing the problem?



I had a similar problem couple of days back, I was trying to write a file, which was opened in read mode by some other function, and when the function ended, the filepointer wasn't closed, hence was causing trouble for the later function to open a write pointer. But as there was no exception being throw, it took me one whole day to debug what was causing the problem as all it returned was False.



Thanks,

Mateen



3 REPLIES 3
YMinaev
Staff

RE: how to debug Exception during file read/write

Hi,



> How do I make the code to throw an exception with what is causing the problem?

There is no way to do this. Check whether the 'path+fileName+".mht"' expression returns a valid fully-qualified file name. Also, try to reproduce the problem when TC is running with administrator permissions.

------
Yuri
TestComplete Customer Care Engineer

Did my reply answer your question? Give Kudos or Accept it as a Solution to help others. ⬇️⬇️⬇️
mateenhussain
Occasional Contributor

RE: how to debug Exception during file read/write

Hi Jared



As I replied in my email, it was the problem of file pointers, not invalid filename or path. But what I was intrested was, is there a better way to find out, either by exception handling or some other technique to find out the exact exception which could save loads of time.



Thanks,

Mateen

RE: how to debug Exception during file read/write

Hi Mateen,


Currently, the exact cause of failing to export logs by the Log.SaveResultsAs method cannot be obtained from script. However, I have registered your request as a suggestion in our DB.



Best regards,
Alexey

Did my reply answer your question? Give Kudos or Accept it as a Solution to help others. ⬇️⬇️⬇️
cancel
Showing results for 
Search instead for 
Did you mean: