强制每个Inside方法必须抛出或强制不使用try catch块。
下面的示例InsideMethod2()
在throw
方法中被调用时,Main()
并不是强制性的,应给出警告或错误消息,说明您必须throw
或不应使用try
catch
块。
示例:
public void Main()
{
try
{
InsideMethod1();
InsideMethod2();
}
catch (System.Exception)
{
throw;
}
}
public int InsideMethod1()
{
try
{
// implementation here
}
catch (System.Exception)
{
// log
throw;
}
}
public int InsideMethod2()
{
// enforce throw or enforce not use try catch block
int a = 1, b = 0, c = 0;
try
{
c = a / b;
}
catch (System.Exception)
{
// enforce to throw
// log
}
return c;
}
是否可以强制执行内部方法??