이 코드를 코드에 명시 적으로 지정하고 이러한 오류를 자동으로 기록하거나 특수 처리기를 호출하려는 경우 해당 코드를 래핑하기 위해 사용자 지정 처리를 사용하여 템플릿을 구현할 수 있습니다. 예 :
proc throwPair(value: int) =
if (value mod 2) != 0:
echo "Passed for ", value
else:
raise newException(ArithmeticError, "Bad value")
template ignoreArithmetic(body: stmt): stmt {.immediate.} =
try: body
except ArithmeticError: discard
template ignoreArithmeticAndLog(body: stmt): stmt {.immediate.} =
try: body
except ArithmeticError:
echo "Did ignore arithmetic error!"
proc tester() =
for f in 0..10:
ignoreArithmeticAndLog:
throwPair f
tester()
당신이하고있는 일은 자연스러운 일입니다. 어쩌면 catch 메소드에 대한 정보를 기록하여 실패한 인스턴스를 참조 할 수 있습니다. –