1

私は Ray の『ColdFusion アプリケーションにエラー処理を追加するための完全なガイド』を読んでいて、利用可能な値のいくつかに興味をそそられていますがonError、スクリプト化された で関数を使用していますApplication.cfc

Learn.adobe.comによると、cferror には診断エラー変数と、 や などのその他の興味深いビットがerror.remoteAddressありerror.generatedContentます。

Q:スクリプト化された Application.cfc で onError を使用している場合、診断エラー変数を (他の変数と共に) 取得するにはどうすればよいですか?

編集:正確にどのように使用していonErrorますか?

public void function onSessionStart() {
    session.TryCatch = 3;
}

public boolean function onRequestStart(String targetPage){
    request.TickCount = GetTickCount();
    request.LogDBSort = 0;
    return true;
}

public void function onError(Exception,EventName) {
    if (StructKeyExists(session,"TryCatch") && session.TryCatch) {
        session.TryCatch -= 1;
        if (StructKeyExists(Exception,"Message")) {
            WriteOutput("It looks like you got the following ColdFusion error:<blockquote>"
                & Exception.Message
                & "</blockquote>"
            );
            local.LogCFErrMessage = Exception.Message;
        } else {
            local.LogCFErrMessage = "No Exception.Message";
        }
        param request.TickCount = GetTickCount();
        param request.LogDBSort = -999;
        request.LogDBSort += 1;

        if (StructKeyExists(Exception,"Name")) {
            local.LogCFErrName = Exception.Name;
        } else {
            local.LogCFErrName = "No Exception.Name";
        }
        if (StructKeyExists(Exception,"Detail")) {
            local.LogCFErrDetail = Exception.Detail;
        } else {
            local.LogCFErrDetail = "No Exception.Detail";
        }
        if (StructKeyExists(Exception,"Number")) {
            local.LogCFErrNumber = Exception.Number;
        } else {
            local.LogCFErrNumber = "No Exception.Number";
        }
        if (StructKeyExists(Exception,"Type")) {
            local.LogCFErrType = Exception.Type;
        } else {
            local.LogCFErrType = "No Exception.Type";
        }
        if (StructKeyExists(Exception,"EventName")) {
            local.LogCFErrEventName = Exception.EventName;
        } else {
            local.LogCFErrEventName = "No Exception.EventName";
        }
        local.svc = new query();
        local.sql = "
        DECLARE @LogCFErrSort Int = #Val(request.LogDBSort)#;
        DECLARE @LogCFErrNumber Int = #Val(local.LogCFErrNumber)#;
        DECLARE @LogCFErrElapsed Int = #GetTickCount() - request.TickCount#;
        INSERT INTO LogCFErr
        (LogCFErrSort, LogCFErrNumber, LogCFErrElapsed,LogCFErrName,LogCFErrDetail,LogCFErrMessage,LogCFErrType,LogCFErrEventName) VALUES(
        @LogCFErrSort,@LogCFErrNumber,@LogCFErrElapsed,?,?,?,?,?)
        ";
        local.svc.setSQL(local.sql);
        local.svc.addParam(cfsqltype="CF_SQL_VARCHAR",value=Left(local.LogCFErrName,512));
        local.svc.addParam(cfsqltype="CF_SQL_VARCHAR",value=Left(local.LogCFErrDetail,512));
        local.svc.addParam(cfsqltype="CF_SQL_VARCHAR",value=Left(local.LogCFErrMessage,512));
        local.svc.addParam(cfsqltype="CF_SQL_VARCHAR",value=Left(local.LogCFErrType,512));
        local.svc.addParam(cfsqltype="CF_SQL_VARCHAR",value=Left(local.LogCFErrEventName,512));
        local.svc.execute();
        if (IsDefined("Application.Home.Email.UserName")) {
            local.svc = new mail();
            local.svc.setSubject(GetApplicationMetaData().Name & ': ' & ListLast(GetBaseTemplatePath(),'\'));
            local.msg = LogCFErrMessage;
            local.svc.setBody(local.msg);

            local.svc.setServer(Application.Home.Email.Server);
            local.svc.setType(Application.Home.Email.Type);
            local.svc.setUseSSL(Application.Home.Email.UseSSL);
            local.svc.setPort(Application.Home.Email.Port);
            local.svc.setFrom(Application.Home.Email.UserName);
            local.svc.setUserName(Application.Home.Email.UserName);
            local.svc.setPassword(Application.Home.Email.Password);
            local.svc.setTo(Application.Home.Email.UserName);
            local.svc.Send();
            WriteOutput("I've sent an email to the administrator to let them know.");
        }
    }
}
4

1 に答える 1

1

私はarguments.exceptionを使用します。ここに例があります。

<cffunction name="onError">
<cfargument name="Exception" required=true type="any">
 more code

<cfmail to="#recipients#" 
from="#recipients#" 
subject="Error on whatever" type="html">

<p>Error Occurred #now()#</p> 
<cfdump var="#Arguments.Exception#" label="exception">
<cfdump var="#request#" label="request">
<cfdump var="#cgi#" label="cgi">
</cfmail>
于 2013-11-09T21:21:38.153 に答える