我需要了解java异常处理的优先级。执行捕捉优先级
我有一个类控制器,有一个类NodeManager具有类NameManager。 NameManager有一个方法:
public LriNode getLriNode(...) throws HttpErrorException
{
if(condition)
throw new HttpErrorException (status);
}
类节点管理器使用中的前一个方法如下
public void nodeWriter(...) throws HttpErrorException
{
...
try
{
//this can throw an HttpErrorExeption
lriNode = nameManager.getLriNode(resourceName);
...
}
catch (HttpErrorException e)
{
if(e.getStatus().name().equals(HttpStatus.NOT_FOUND))
{
//here can be thrown an HttpErrorExeption too
do work
}
else
{
e.printStackTrace();
}
}
}
终于类控制器使用下列
@RequestMapping(method=RequestMethod.PUT, value="document/{name}")
public ModelAndView putDocument(@RequestBody String body, @PathVariable String name, HttpServletResponse response, HttpServletRequest request)
{
Source source = new StreamSource(new StringReader(body));
try
{
NodeManager.nodeWriter(...);
return new ModelAndView(XML_VIEW_NAME, "document", document);
}
catch (HttpErrorException e)
{
response.setStatus(e.getStatus().value());
e.printStackTrace();
}
return null;
}
那么前面的方法,那就是:当NameManager抛出一个HttpErrorException
时,我期望NodeManger的内的try-catch块方法将执行到例外。它发生的是该控件返回到Controller类,并且它的try-catch块被执行。看起来nodeWriter()
方法中的throws HttpErrorException
语句在内部try-catch块上具有优先级。
任何人都可以解释我这样的异常处理优先系统吗?
据我所知,目前还没有这样的异常处理优先系统。正如你指出的那样,你可以在NodeWrite的catch语句中引发HttpErrorExeption。我认为是这样。 – darlinton