Search code examples
error-handlingerror-logging

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


I have this code in 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")

Should i write message twice? Or should i only log the error and throw empty exception?


Solution

  • It depends, use cases to use cases. If your log statement is within dev-scope then there is no need to throw exception to the source/caller. you can log exception and silent it and return back useful message/code to source/caller.