2016-07-13 1 views
-1

파일 "쓰기"작업 중에 발생할 수있는 오류를 처리 할 수 ​​있는지 궁금해 할 때.cffile "쓰기"작업에서 오류 처리

Adobe의 Coldfusion 웹 사이트 나 인터넷 검색에서 아무 것도 발견하지 못했습니다.

하나는 단순히 오류 처리없이

<cffile action="write" file="#filename#" output="#trim(content)#" /> 

같은 것을 쓸 수 있습니까? 안전 해요?

+2

무엇으로부터 안전합니까? –

+0

운영 체제가 디스크에 대한 쓰기 처리를 담당하므로 파일 작업이 안전하지 않습니다. 권한이 실패하거나, 파일 잠금이되어 디스크가 가득 찰 수 있습니다. 아래의 답변에서 이미 제안 된대로'try/catch'를 사용하십시오. – Alex

답변

3

물론 오류 처리를 사용해야합니다. ColdFusion에는 다른 언어와 마찬가지로 try/catch가 있습니다. Read the documentation on the cftry tag here.

당신은 적어도이 같은 try/catch 블록에서 해당 코드를 포장 할 수 있습니다

<cftry> 
    <cffile action="write" file="#filename#" output="#trim(content)#" /> 
    <cfcatch type="any"> 
     <!--- do what is needed here to handle the error ---> 
    </cfcatch> 
</cftry> 

하지만 당신은 또한뿐만 아니라 처리 약간의 전반적인 오류를 사용한다. Read about overall error handling in ColdFusion here.