0
class 1:
public static void TypeOneException2TypeTwoException(TypeOneException exception)
                throws TypeTwoException {
            if (exception == null)
                throw new IllegalArgumentException(
                        "TypeOneException shouldn't be null"); 
            LOG_SERVICE.debug(exception.getMessage(), exception);  //log it

            if (exception instanceof TypeTwoException)
                throw new TypeTwoException(
                        DavServletResponse.SC_METHOD_NOT_ALLOWED,
                        exception.getMessage());


class 2:
public void callerOne(){
            try{

            }catch(TypeOneException exception){
                LOG_SERVICE.debug(exception.getMessage(), exception);  //is still need log it? any benifit?
                TypeOneException2TypeTwoException(exception)
            }

class 3:
public void callerTwo(){
            try{

            }catch(TypeOneException exception){
                LOG_SERVICE.debug(exception.getMessage(), exception); //is still need log it?
                TypeOneException2TypeTwoException(exception)
            }

class 4:
public void callerTwo(){
            try{

            }catch(TypeOneException exception){
                LOG_SERVICE.debug(exception.getMessage(), exception); //is still need log it?
                TypeOneException2TypeTwoException(exception)
            }

as titled. I have logged the error in class1. if has any need to log it in callers(class2,3,4)? if need, any benifits existed? Thanks in advance. Suppossed need, if the duplicate code existed?

4

1 回答 1

0

在多个级别进行日志记录没有任何问题。在许多情况下,记录并引发异常的较低级别的调用将用于较大操作的上下文中。因此,它有助于通过在更高级别记录它来为正在发生的事情添加上下文。

请记住,日志记录是可配置的,因此您可以为每个记录器打开/关闭日志记录(通常按类级别隔离)。

于 2012-07-11T02:03:31.597 回答