1.异常抛出
封装API时,如果参数为必填项,检测参数不合格时,应当抛出传入参数不正确的异常(绝对不允许的错误,也应该抛出异常)
public int test(string arg1, string arg2, out string msg){
if(string.IsNullOrEmpty(arg1))
throw new Exception("arg1 不能为空");
}
封装API时,如果参数没有限制,当执行过程中,因参数问题导致程序出错,则应将参数的问题返回
public int test(string arg1, string arg2, out string msg){
int result = Fun_Test(arg1);
//result 结果表示的意思是执行失败,则根据result的类型,来指定错误内容
if(result == -1){
msg = "***********";
}
return -1
}