none
Programs quits execution without any error or exception which I can see but also before reaching the end of the code. RRS feed

  • Question

  • Hi,

    I have written a c# program, using Visual Studio 12 Ultimate, which GetsFiles from a directory, finds their owner, size, create date time, modified date time, access time etc. This directory is very large, about 940 Gig. Some files have names which can cause exceptions like “&” in the name, or the path name is too long etc.. For some files the owners have been deleted, but the SID can still be determined for such files.

    Because of all the above issues, the program throws an exception, which gets handled in the catch clause, the file name which caused the exception is saved so that next time it is bypassed, and then program exits the catch clause and start looping through the files again. So far so good.

    This program runs for a very long time. And eventually, it quits or ends without throwing any final exception, but at the same time I do not think it is successfully completing either, because it is not reaching the last line of the code. It skips it and enters the “finally” clause. I have a break point at the last line of the code. It never gets hit. I have placed try catch around all the statements, in the Main method, which are executed. I have break points on all the catch statements themselves, they never get hit either. Because it is skipping the last line of the code and directly entering the finally clause, I think that an undetectable exception is occurring. Is that possible ? Is something else going on ? How can I debug and find out, what is the error ?

    Help Appreciated.

    Thank you

    Diane


    diana4


    • Edited by Diana4 Sunday, June 17, 2018 9:28 PM
    Sunday, June 17, 2018 9:23 PM

Answers

  • No, it is not multi threaded application. 

    Could I use something like this ?

    https://msdn.microsoft.com/en-us/library/system.appdomain.unhandledexception(v=vs.110).aspx



    diana4

    I don't see why not and write to a log file or to the system events.

    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    • Marked as answer by Diana4 Monday, June 18, 2018 7:22 PM
    Monday, June 18, 2018 2:10 PM
    Moderator
  • GetFiles returns an array. To get that array it blocks while it enumerates all the files. If at any point during the enumeration the process fails (such as permissions) then the entire call fails. Hence if you were to point to something like C:\Windows then you'd never get any results. 

    EnumerateFiles is the preferred approach these days as it allows you to enumerate the files item by item. It will still throw an exception but only at the point it gets to a file it cannot retrieve. Is that ultimately causing your issues? Unlikely, just a suggestion.

    Out of memory will raise an OutOfMemoryException so you can handle it normally. However it is always fatal. There is nothing you can do to prevent your process from crashing. Additionally, because memory is gone you cannot do much as anything that might allocate memory would fail. Recovering from this error is very difficult. Still, it is unclear whether you're actually running out of memory or not. When your app crashes Windows should generate a WER message which will tell you why your app went down. If you aren't getting that then it probably isn't an exception that is occurring.

    I would recommend that you put some sort of finished message in your output so you can tell when you're done. 


    Michael Taylor http://www.michaeltaylorp3.net

    • Marked as answer by Diana4 Monday, June 18, 2018 7:21 PM
    Monday, June 18, 2018 3:14 PM
    Moderator
  • You're seeing this issue while running the app in the debugger? If so then any unhandled exception would break into the debugger. If the debugger isn't breaking then it likely isn't an exception. Your breakpoint may not be in a place that would get triggered. You might want to look for any pre-mature exit logic in your app and perhaps moving the breakpoint further up in the code.

    Michael Taylor http://www.michaeltaylorp3.net

    • Marked as answer by Diana4 Monday, June 18, 2018 7:21 PM
    Monday, June 18, 2018 3:49 PM
    Moderator
  • Hello,

     As the others have stated, use some code that lets you know progress. This can be

    as simple as Console.WriteLine method to display at what point code is about to execute.

    Your telling us that you handle exceptions without problems.  But at the same time, you

    think your code is not executing properly. For what reason do you suspect failed execute?

    What are the results if the code/app completes as intended? Have you code any kind of

    results report or does the app just exit?  Every coder as their style and recursive methods

    are fairy straight forward implementations.  We really need to see your code and put in

    action for a more concise resolution.

     

     Thanks :)

    • Marked as answer by Diana4 Monday, June 18, 2018 7:21 PM
    Monday, June 18, 2018 3:52 PM

All replies

  • The only thing you can do is start logging some strategic messages to a text file as to what the program is doing at certain points so that you can see what is going on and hopefully pinpoint the problem. 
    Monday, June 18, 2018 2:45 AM
  • Is it multithread application?
    • Edited by Petr B Monday, June 18, 2018 9:14 AM
    Monday, June 18, 2018 9:14 AM
  • No, it is not multi threaded application. 

    Could I use something like this ?

    https://msdn.microsoft.com/en-us/library/system.appdomain.unhandledexception(v=vs.110).aspx



    diana4

    Monday, June 18, 2018 1:37 PM
  • No, it is not multi threaded application. 

    Could I use something like this ?

    https://msdn.microsoft.com/en-us/library/system.appdomain.unhandledexception(v=vs.110).aspx



    diana4

    I don't see why not and write to a log file or to the system events.

    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    • Marked as answer by Diana4 Monday, June 18, 2018 7:22 PM
    Monday, June 18, 2018 2:10 PM
    Moderator
  • You can capture all exceptions in using the AppDomain.Unhandled event. However it sounds like you should already be catching this exception because of your exception handling code. You should take a look at your logs and see what the last set of exceptions were.

    There could be any # of things that could be going wrong. Out of memory comes to mind. If you're enumerating arbitrary directories then permissions come into play. Hopefully you aren't trying to use GetFiles or GetDirectories for this. For most other scenarios you shouldn't need a lot of exception handling. A missing user, for example, wouldn't cause an exception because you have the original SID. If you tried to convert it to a user name that may not work but the SID should be valid.

    File names with & shouldn't cause any issue. There are only a limited set of characters that aren't allowed (Path.GetInvalidFileNameChars).


    Michael Taylor http://www.michaeltaylorp3.net

    • Marked as answer by Diana4 Monday, June 18, 2018 2:23 PM
    • Unmarked as answer by Diana4 Monday, June 18, 2018 2:31 PM
    Monday, June 18, 2018 2:14 PM
    Moderator
  • Actually, I do use Directory.GetFiles to get all the files and store them into a string Array. Then I loop through all the members of the string Array.

    Can you tell me what is wrong with using GetFiles please ? Would out of memory error not manifest as an exception ? how can detect it ? The program runs for a day at least before quitting. It ends up giving me quite a haul of information on the files I am looking for. I just do not know if it is all of it, or there is still more

    Thanks


    diana4

    Monday, June 18, 2018 2:38 PM
  • GetFiles returns an array. To get that array it blocks while it enumerates all the files. If at any point during the enumeration the process fails (such as permissions) then the entire call fails. Hence if you were to point to something like C:\Windows then you'd never get any results. 

    EnumerateFiles is the preferred approach these days as it allows you to enumerate the files item by item. It will still throw an exception but only at the point it gets to a file it cannot retrieve. Is that ultimately causing your issues? Unlikely, just a suggestion.

    Out of memory will raise an OutOfMemoryException so you can handle it normally. However it is always fatal. There is nothing you can do to prevent your process from crashing. Additionally, because memory is gone you cannot do much as anything that might allocate memory would fail. Recovering from this error is very difficult. Still, it is unclear whether you're actually running out of memory or not. When your app crashes Windows should generate a WER message which will tell you why your app went down. If you aren't getting that then it probably isn't an exception that is occurring.

    I would recommend that you put some sort of finished message in your output so you can tell when you're done. 


    Michael Taylor http://www.michaeltaylorp3.net

    • Marked as answer by Diana4 Monday, June 18, 2018 7:21 PM
    Monday, June 18, 2018 3:14 PM
    Moderator
  • Thank you. I use GetFiles only once, in the beginning. It gets all the files into an Array. After that I use only the Array. Loop through it. it is exiting the Array, for each loop. Because the GetFiles statements is executing successfully every time, that means, it is not the problem, right now.

    But it is helpful information. Thanks for information on Enumerate Files.

    So, currently, I do have a breakpoint at the last statement of main method, which never gets hit.

    Thank you for all your help. I will play around and see if something else comes forth.



    diana4

    Monday, June 18, 2018 3:36 PM
  • You're seeing this issue while running the app in the debugger? If so then any unhandled exception would break into the debugger. If the debugger isn't breaking then it likely isn't an exception. Your breakpoint may not be in a place that would get triggered. You might want to look for any pre-mature exit logic in your app and perhaps moving the breakpoint further up in the code.

    Michael Taylor http://www.michaeltaylorp3.net

    • Marked as answer by Diana4 Monday, June 18, 2018 7:21 PM
    Monday, June 18, 2018 3:49 PM
    Moderator
  • Hello,

     As the others have stated, use some code that lets you know progress. This can be

    as simple as Console.WriteLine method to display at what point code is about to execute.

    Your telling us that you handle exceptions without problems.  But at the same time, you

    think your code is not executing properly. For what reason do you suspect failed execute?

    What are the results if the code/app completes as intended? Have you code any kind of

    results report or does the app just exit?  Every coder as their style and recursive methods

    are fairy straight forward implementations.  We really need to see your code and put in

    action for a more concise resolution.

     

     Thanks :)

    • Marked as answer by Diana4 Monday, June 18, 2018 7:21 PM
    Monday, June 18, 2018 3:52 PM
  • I will try resolving based on your suggestions. If not I will post the code... 

    Thank you all


    diana4

    Monday, June 18, 2018 7:21 PM