코드의 try catch 블록에서 예외를 catch하려고합니다. 잘못된 암호/파일과 같은 특정 오류 메시지가 있으며 오류가 발견되면 코드를 설정하려고합니다. 스위치를 사용하여 메시지를 잡으려고합니다. switch 문을 사용하여 메시지 캐치 시도
catch (Exception ex)
{
switch (ex.Message.ToString())
{
case "Can't get attributes of file 'p'":
Debug.WriteLine("wrong username/password");
MainController.Status = "2";
break;
case "Can't get attributes of file 'p'.":
Debug.WriteLine("File is not Available");
MainController.Status = "3";
break;
default:
Debug.WriteLine("General FTP Error");
MainController.Status = "4";
break;
}
}
나는 내가 ex.message의 오류 메시지의 일부를 얻을 경우 다음이 관련 사건을 호출 할 수 있도록 message.contains 방법을 사용하고 싶지만 내가 예를 사용하는 방법을 알아낼 수 없습니다입니다
.message.contains. 누구든지 나를 도울 수 있습니까?
만약'Contains'를 사용하고 싶다면'switch'를 포기하고 대신'if ... else'를 사용해야합니다. – jmcilhinney