제목이 약간 잘못 될 수도 있습니다.하지만 내가 원하는 것은 파일 배열을 읽은 다음 하나의 요소로 결합하여 현재 위치하는 것입니다.예외를 캐치 한 다음 예외를 던집니다/예외를 보내고 계속합니다.
문제점은 "FileNotFoundException"예외를 찾는 catch가 있는데 내 try 문 ("계속 사용")을 계속하고 싶지만 사용자에게 파일이 없다는 것을 알리면됩니다.
내 설정은 내 양식에서 등록 할 수있는 이벤트를 만드는 방법에 대해 생각
형태 (오류가 표시되어야 곳이 형태의)에서 호출되는 클래스이지만, 권리이다 방법? 목록이 비어 있지 경우
public void MergeClientFiles(string directory)
{
// Find all clients
Array clients = Enum.GetValues(typeof(Clients));
// Create a new array of files
string[] files = new string[clients.Length];
// Combine the clients with the .txt extension
for (int i = 0; i < clients.Length; i++)
files[i] = clients.GetValue(i) + ".txt";
// Merge the files into directory
using (var output = File.Create(directory))
{
foreach (var file in files)
{
try
{
using (var input = File.OpenRead(file))
{
input.CopyTo(output);
}
}
catch (FileNotFoundException)
{
// Its here I want to send the error to the form
continue;
}
}
}
}
나는이 대답과 함께 갈 것이라고 생각합니다. 메소드가 오류를 리턴하고 양식이보고 할 오류가 있는지 파악할 수 있도록하는 것이 좋습니다. – Dumpen