如果遇到逻辑错误错误(过期用户,无效ID),那么从以下方面告诉父方法此错误的最佳方法是什么:
1-抛出自定义异常,如下所示:
try { //if (ID doesn't match) then Throw new CustomException(-1,"ID doesn't match"); } catch(CustomException ex) { throw ex } catch(Exception ex) { throw new CustomException(ex.ErrorCode,ex.message); }
//if (ID doesn't match) then This.ErrorCode= -1; This.Message= "ID doesn't match";