Although not specifically specified in the language, if the
try-catch encounters an error, you want to save the error as a log (
WriteExceptionToLogFile section of the code below).
Up until now, I have used the above code, but considering that
WriteExceptionToLogFile causes errors, I have noticed that there are two problems.
WriteExceptionToLogFilecauses an error where the program stops
WriteExceptionToLogFileIn addition to not knowing its own errors, you will not know the exceptions that were supposed to be written by
Is there a way to resolve the above two issues when a logger running in the
catch section stops due to an error, or is there an implicit understanding that the logger does not generate an error in the first place?
WriteExceptionToLogFile causes an error, where the program stops
I think the word "error" means "Exception", but if an exception is likely to be thrown within
WriteExceptionToLogFile, catch it and continue to process it, the program will not stop.
WriteExceptionToLogFile I don't know my own error, and I don't know the exceptions that were supposed to be written by
You can catch an exception thrown in
WriteExceptionToLogFile and print the exception and the original exception to another file.However, if writing to the log file fails, it would be better to output it to something other than the log file, such as the standard (error) output, because it is a very exception case such as insufficient disk space.
© 2023 OneMinuteCode. All rights reserved.