Unknown IOException Keeps Bugging Me

C

Carlos

Dear All,

I have written a very simple class with the following constuctor. The
project is a PPC project. When the line comes to "using (...)", it
immediately jumps to the "catch" clause without knowing the reason. I have
tried different code, but I just can write a file, but not open the open for
read. Can anyone give me some help?

Regards,
Carlos

try
{
// if ( File.Exists(fileName) )
// File.Delete(fileName);

// The using statement also closes the StreamReader.
using (StreamReader sr = new StreamReader(fileName))
{
String line;
// Read and display lines from the file until the end of
// the file is reached.
while ((line = sr.ReadLine()) != null)
{
Console.WriteLine(line);
u.Items.Add(line);
}
}

}
catch ( Exception e )
{
MessageBox.Show(e.Message);
}
 
S

Sergey Bogdanov

I do not see anything strange. Can you show us a sample which
demonstrates the issue?
 
C

Carlos

Problem rectified. I have opened an opened file in the try-catch block~

Thanks~
Carlos

Sergey Bogdanov said:
I do not see anything strange. Can you show us a sample which demonstrates
the issue?

--
Sergey Bogdanov [.NET CF MVP, MCSD]
http://www.sergeybogdanov.com

Dear All,

I have written a very simple class with the following constuctor. The
project is a PPC project. When the line comes to "using (...)", it
immediately jumps to the "catch" clause without knowing the reason. I
have tried different code, but I just can write a file, but not open the
open for read. Can anyone give me some help?

Regards,
Carlos

try
{
// if ( File.Exists(fileName) )
// File.Delete(fileName);

// The using statement also closes the StreamReader.
using (StreamReader sr = new StreamReader(fileName))
{
String line;
// Read and display lines from the file until the end of
// the file is reached.
while ((line = sr.ReadLine()) != null)
{
Console.WriteLine(line);
u.Items.Add(line);
}
}

}
catch ( Exception e )
{
MessageBox.Show(e.Message);
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top