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)
            }

タイトル通り。class1 にエラーを記録しました。発信者 (class2,3,4) にログインする必要がある場合は? 必要に応じて、メリットはありましたか? 前もって感謝します。重複したコードが存在する場合、必要だと思われますか?

4

1 に答える 1

0

複数のレベルでログを記録することに問題はありません。多くの場合、例外をログに記録してスローする下位レベルの呼び出しは、より大きな操作のコンテキストで使用されます。そのため、より高いレベルでログを記録することで、何が起こっていたかにコンテキストを追加するのに役立ちます。

ロギングは構成可能であるため、各ロガー (通常はクラス レベルで分離) のロギングをオン/オフできることに注意してください。

于 2012-07-11T02:03:31.597 に答える