我应该在日志或内部异常或两者中打印错误消息吗?

Should i print error message in logs or inside exception or both?

我在 Scala 中有这段代码:

logger.error("Repository does not exists or does not contains 'definitions' directory")
throw new FileNotFoundException("Repository does not exists or does not contains 'definitions' directory")

我应该写两次消息吗?或者我应该只记录错误并抛出空异常?

视情况而定,用例到用例。 如果您的日志语句在开发范围内,则无需向 source/caller 抛出异常。您可以记录异常并将其静音,然后 return 返回有用的 message/code 到 source/caller.