我有这样的事情:不能捕捉异常
...
while (itr.hasNext()) {
...
try {
if (userInput.equalsIgnoreCase(theData.getName())
|| (country.getName().toString()).equalsIgnoreCase(theData.getName()))
{
result = new Country(PointT, dist);
break;
} else {
for (int i = 0; i < repl.size(); i++) {
if (repl.get(i).toString().contains(theData.getName())) {
theName = true;
result = new Country(PointTt, dist, theName);
break;
} else if (theParts.get(i).toString().equalsIgnoreCase(theData.getName())) {
result = new Country(PointT, dist);
break;
}
}
}
} catch (NoSuchElementException ex) {
logger.error("Does not exist in database", ex);
throw ex;
} catch (NullPointerException ex) {
logger.error("Does not exist in database", ex);
throw ex;
}catch (Exception ex) {
logger.error("Does not exist in database", ex);
throw ex;
}
}
...
所以,我用theData.getName()
相比,userInput
这仅仅是一个字符串,country.getName()
这是也是一个字符串,repl.get(i)
这是一个List<String>
,theParts.get(i)
这也是一个List<String>
。
我找不到解决方案来完成这项工作。在数据库中不存在字符串(theData.getName())
时抛出异常。
读取数据
为了读取theData
:
我使用FileInputStream fis = new FileInputStream(filelocation);
然后,只提取的字符串,并将其储存:
ArrayList<String> theNames = new ArrayList<String>();
,然后我将theNames
与其他迭代器合并并创建
ArrayList<theNamesLoc> theNamesLocList = new ArrayList<theNamesLoc>();
而这正是我申请了数组列表:
Iterator<TheNamesLoc> itr = theNamesLocList.iterator();
while (itr.hasNext()) {
..}
if(!next())throw ..?类似的东西?你不显示你如何阅读你的数据,那么我们应该怎么知道? – Stultuske
是数据null?你在使用前先检查它吗? – Assafs
if(theData == null)如何抛出xyzException? – procrastinator