void ReadFile(int index)
{
// To run this code, substitute a valid path from your local machine
string path = @"c:\users\public\test.txt";
System.IO.StreamReader file = new System.IO.StreamReader(path);
char[] buffer = new char[10];
try
{
file.ReadBlock(buffer, index, buffer.Length);
}
catch (System.IO.IOException e)
{
Console.WriteLine("Error reading from {0}.
Message = {1}", path, e.Message);
}
finally
{
if (file != null)
{
file.Close();
}
}
// Do something with buffer...
}
를 사용하고 사용하지 않을의 차이점은 무엇입니까?
void ReadFile(int index)
{
// To run this code, substitute a valid path from your local machine
string path = @"c:\users\public\test.txt";
System.IO.StreamReader file = new System.IO.StreamReader(path);
char[] buffer = new char[10];
try
{
file.ReadBlock(buffer, index, buffer.Length);
}
catch (System.IO.IOException e)
{
Console.WriteLine("Error reading from {0}.
Message = {1}", path, e.Message);
}
if (file != null)
{
file.Close();
}
// Do something with buffer...
}
catch 블록은 오류를 다시 발생시키고 새 오류를 발생시킬 수 있습니다. 여기를 참조하십시오 - http://stackoverflow.com/questions/50618/what-is-the-point-of-theallyfin-block – StuartLC
다른 사람이 내가 할 수있는 것보다 빨리 대답을 타이핑 할 것이지만, IOException 및 자신에 대한 차이를보고? – ChaosPandion