Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FileNotFoundException in File.AppendAllText

Tags:

c#

io

I was reading File.AppendAllText method from msdn

http://msdn.microsoft.com/en-us/library/ms143356.aspx

I saw they have listed FileNotFoundException to possible exceptions list for the method but according to there description about method on the same page

Opens a file, appends the specified string to the file, and then closes the file. If the file does not exist, this method creates a file, writes the specified string to the file, then closes the file.

this part

If the file does not exist, this method creates a file

it seems this exception can never be thrown for this method.

like image 843
Pawan Nogariya Avatar asked Jan 31 '13 13:01

Pawan Nogariya


1 Answers

If you take a look at (say) Mono's implementation (which is compatible with Microsoft's), all File.AppendAllText ends up doing (argument checks aside) is creating a StreamWriter with your path and calling a Write on that object.

Neither the used constructor nor the method are listed anywhere to throw a FileNotFoundException, as far as I can tell, so it might be a documentation error.

like image 163
Theodoros Chatzigiannakis Avatar answered Sep 22 '22 07:09

Theodoros Chatzigiannakis