spring有使用catch做逻辑判断

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/u012817635/article/details/85955703

这里,是spring DefaultResourceLoader 中的代码片段,逻辑是location是否可以转换成java.net.URL,这里的配置文件我配置的并非url,所以转换的时候会抛异常进入catch,异常是no protocol,没有这个协议,在catch里面spring直接走了非url的逻辑。

平时写代码的时候我极力避免这种case,但其实发现简单的在catch中处理一些简单逻辑,也并非不可。有spring给我撑腰,下次再让我check那种不好check的case,我直接catch就ok了,哈哈哈哈

展开阅读全文

在Ant中使用逻辑判断 Condition

04-19

在Ant中使用逻辑判断 Condition .rn分类: J2SE 2008-05-13 23:19 4528人阅读 评论(3) 收藏 举报 rn 好久不写ant脚本了,最近两天在用ant做web应用的安装部署脚本,为了实现web服务器的多版本兼容,必然要使用逻辑判断,比如我要判断是安装在weblogic8上还是weblogic9上,而在ant中处理逻辑判断真是麻烦,只能作用于task,要利用property来做判断,使用available来设置property。例如:rnrnrnrn rn rn rn rn rn rn rn rn rn rn rn rn rnrn上面判断一个文件,如果存在的话 fileIsExists 就为true,echoDemo这个task在执行前会先判断fileIsExists 是否为true如果不为true就不执行了。c盘下面有123.txt的话会打印hello ant 否则不会打印。rnrn这里面还有一个小陷阱,我习惯使用antcall,不喜欢使用depends,但是使用antcall的话就会有问题,例如我最开始这么写的,就不行。rnrnrnrn rn rn rn rn rn rn rn rn rn rn rn rn rn rnrnrn使用antcall的话在echoDemo这个task执行的时候fileIsExists这个属性永远不为true,即便在执行完detect.file后它已经为true了,但是它不会被传递到下一个task,没用深入研究过ant,所以具体内部实现还不了解。rnrn下面是ant的官方参考文档rnrn更复杂的可以参考rnrnhttp://ant.apache.org/manual/CoreTasks/conditions.htmlrnrnConditionrnDescriptionrnSets a property if a certain condition holds true - this is a generalization of Available and Uptodate.rnrnIf the condition holds true, the property value is set to true by default; otherwise, the property is not set. You can set the value to something other than the default by specifying the value attribute.rnrnConditions are specified as nested elements, you must specify exactly one condition.rnrnParametersrnrnAttribute Description Required rnproperty The name of the property to set. Yes rnvalue The value to set the property to. Defaults to "true". No rnelse The value to set the property to if the condition evaluates to false. By default the property will remain unset. Since Ant 1.6.3 No rnrnrnParameters specified as nested elementsrnAll conditions to test are specified as nested elements, for a complete list see here.rnrnExamplesrn rn rn rn rn rn rnsets the property javamail.complete if both the JavaBeans Activation Framework and JavaMail are available in the classpath.rnrn rn rn rnrn rn rnrn rn rn rnsets the property isMacOsButNotMacOsX if the current operating system is MacOS, but not MacOS X - which Ant considers to be in the Unix family as well.rnrn rn rnrn rnsets the property isSunOSonSparc if the current operating system is SunOS and if it is running on a sparc architecture.rnrn 论坛

有关try和catch使用

06-11

BOOL CLogin::PreTranslateMessage(MSG* pMsg) rnrn // TODO: Add your specialized code here and/or call the base classrn if(pMsg->message==WM_KEYDOWN && pMsg->wParam==VK_RETURN)rn rn pMsg->wParam = 9;rn rn if(pMsg->message == WM_LBUTTONDOWN)rn rn CRect rect,rc;rn m_OK.GetWindowRect(&rect);rn m_Cancel.GetWindowRect(&rc);rn CPoint point;rn GetCursorPos(&point);rn if(rect.PtInRect(point))rn rn UpdateData(TRUE);rn if(m_Name.IsEmpty() || m_PassWord.IsEmpty())rn rn MessageBox("用户名或密码不能为空");rn return FALSE;rn rn m_Time++;rn [color=#FF0000]tryrn rn //创建连接对象实例rn m_pConnection.CreateInstance("ADODB.Connection");rn //设置连接字符串rn CString strConnect="DRIVER=Microsoft Access Driver (*.mdb);\rn uid=;pwd=;DBQ=shujuku.mdb;";rn //使用Open方法连接数据库rn m_pConnection->Open((_bstr_t)strConnect,"","",adModeUnknown);rn rn catch(_com_error e)rn rn AfxMessageBox(e.Description());rn rn CString sql;rn sql.Format("select * from tb_user where 用户名 = '%s' and 密码 = '%s'",rn m_Name,m_PassWord);rn m_pRecordset = m_pConnection->Execute((_bstr_t)sql,NULL,adCmdText);rn if(!m_pRecordset->adoEOF)rn rn CDialog::OnOK();rn [/color] elsern rn if(m_Time == 3)rn rn MessageBox("密码3次不正确");rn CDialog::OnCancel();rn rn elsern rn MessageBox("用户名或密码不正确");rn m_Name = "";rn m_PassWord = "";rn UpdateData(FALSE);rn rn rn m_pRecordset->Close();rn m_pConnection->Close(); rn rn if(rc.PtInRect(point))rn rn CDialog::OnCancel();rn rn rn return CDialog::PreTranslateMessage(pMsg);rnrnrn各位,以上是我看的一段有关制作用户登录模块的程序,其中红色字体部分看的云里雾里的,望高人指点,特别是try和catch的那两段,先谢谢了 论坛

没有更多推荐了,返回首页