有的时候会执行catch里面的代码,请问为什么呢?可能100次里面有2-3次会执行catch
public bool Login(string pwd, string domain, string uid, int ProvCode, ref string errmsg,ref int aliasFlag,ref string enterpriseSheetNo,
ref string longNumber, ref string userMobile, ref string realun)
{
try
{
OracleParameter parvalue = new OracleParameter( "paramReturnValue ", 100);
parvalue.Direction = ParameterDirection.Output;
OracleParameter parMsg = new OracleParameter( "paramreturnMsg ",OracleType.NVarChar,200);
parMsg.Direction = ParameterDirection.Output;
OracleParameter parEpId = new OracleParameter( "paramreturnEpId ",-2);
parEpId.Direction = ParameterDirection.Output;
OracleParameter parEpName = new OracleParameter( "paramreturnEpName ",OracleType.NVarChar,200);
parEpName.Direction = ParameterDirection.Output;
OracleParameter parLongNum = new OracleParameter( "paramreturnEpLongNum ",OracleType.NVarChar,50);
parLongNum.Direction = ParameterDirection.Output;
OracleParameter parIsAliaFlag = new OracleParameter( "paramreturnIsAliaFlag ",100);
parIsAliaFlag.Direction = ParameterDirection.Output;
OracleParameter parMobile = new OracleParameter( "paramreturnMobile ",OracleType.NVarChar,50);
parMobile.Direction = ParameterDirection.Output;
OracleParameter parUserNumber = new OracleParameter( "paramreturnUserNumber ",OracleType.NVarChar,50);
parUserNumber.Direction = ParameterDirection.Output;
OracleParameter parPwd = new OracleParameter( "paramPwd ",OracleType.NVarChar,50);
parPwd.Value = pwd;
OracleParameter paramDomain = new OracleParameter( "paramDomain ",OracleType.NVarChar,50);
paramDomain.Value = domain;
OracleParameter paramUserNumber = new OracleParameter( "paramUserNumber ",OracleType.NVarChar,50);
paramUserNumber.Value = uid;
OracleParameter[] cmdpar = new OracleParameter[]
{
paramDomain,
paramUserNumber,
parPwd,
parMsg,
parEpId,
parEpName,parLongNum,parIsAliaFlag,parMobile,parUserNumber,parvalue
};
base.ExecuteProcedure( "Cmail_Admin_Login.Cmail_Login ",cmdpar);
bool loginSuc = false;
if (int.Parse(parvalue.Value.ToString()) == 0) // 成功
{
aliasFlag = int.Parse(parIsAliaFlag.Value.ToString());
enterpriseSheetNo = parEpId.Value.ToString();
longNumber = parLongNum.Value.ToString();
userMobile = parMobile.Value.ToString();
realun = parUserNumber.Value.ToString();
errmsg = "登陆成功! ";
loginSuc = true;
}
else
{
errmsg = parMsg.Value.ToString();
return false;
}
return loginSuc;
}
catch(Exception ex)
{
errmsg = "数据库连接错误! " + ex.Message;
return false;
}
---------------
请大家帮忙看一下,为什么会偶尔执行到 catch 里面的代码吗?
[解决办法]
设一个断点调试一下不就知道那里出错了