Forum Discussion

mateenhussain's avatar
mateenhussain
Occasional Contributor
15 years ago

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

  • 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.

  • mateenhussain's avatar
    mateenhussain
    Occasional Contributor
    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

  • 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.