두 가지 방법을 호출하는 멀티 캐스트 대리인이 있습니다. 첫 번째 메소드와 그 처리에 예외가있는 경우 두 번째 메소드 호출을 계속하는 방법은 무엇입니까? 나는 아래 코드를 첨부하고있다. 아래 코드에서 첫 번째 메서드는 예외를 throw합니다. 하지만 멀티 캐스트 대리인 호출을 통해 두 번째 방법을 계속 실행하는 방법을 알고 싶습니다. 루프 내부멀티 캐스트 대리자의 예외 처리
public delegate void TheMulticastDelegate(int x,int y);
class Program
{
private static void MultiCastDelMethod(int x, int y)
{
try
{
int zero = 0;
int z = (x/y)/zero;
}
catch (Exception ex)
{
throw ex;
}
}
private static void MultiCastDelMethod2(int x, int y)
{
try
{
int z = x/y;
Console.WriteLine(z);
}
catch (Exception ex)
{
throw ex;
}
}
public static void Main(string[] args)
{
TheMulticastDelegate multiCastDelegate = new TheMulticastDelegate(MultiCastDelMethod);
TheMulticastDelegate multiCastDelegate2 = new TheMulticastDelegate(MultiCastDelMethod2);
try
{
TheMulticastDelegate addition = multiCastDelegate + multiCastDelegate2;
foreach (TheMulticastDelegate multiCastDel in addition.GetInvocationList())
{
multiCastDel(20, 30);
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
Console.ReadLine();
}
}
왜 루프 안에 오류 처리를 넣지 않으시겠습니까? 예외가 발생하면 루프를 계속 진행하십시오. – mdcuesta
의견에 감사드립니다. –