I repost my question here because it has been closed on stack overflow
This question could sound stupid but I am new to the logging, displaying and handling exceptions.
Because before I was just doing a big try catch (Exception ex) to get exceptions (test softwares)
But now I am doing a "real" software, which will have a public release.
And I am asking what is the right way of doing those things.
I am using WPF with the .NET Framework 4.7.2, and i'm also using NLog
For now, I did a little code, and I am just asking like a review / advices.
I put that code at startup, so in the app.xaml.cs with a protected override OnStartup()
try {
// Create application main directory
Directory.CreateDirectory(Reference.AppPath);
} catch (Exception ex) {
// Log
Log.Error(ex);
// The path isn't valid/found (ex: with network name)
if (ex is DirectoryNotFoundException || ex is IOException || ex is NotSupportedException) {
MessageBox.Show(string.Format("The application path '{0}' isn't valid..\nPlease check if the path is valid", Reference.AppPath), Reference.AppName, MessageBoxButton.OK, MessageBoxImage.Error);
}
// The user hasn't the permission to write (then need to run the application as administrator)
else if (ex is UnauthorizedAccessException) {
MessageBox.Show(string.Format("The application hasn't the right to write data in the application path '{0}'..\nPlease start the application as administrator", Reference.AppPath), Reference.AppName, MessageBoxButton.OK, MessageBoxImage.Error);
}
// Path is too long (max: 256 chars)
else if (ex is PathTooLongException) {
MessageBox.Show(string.Format("The application path '{0}' is too long..\nPlease install the application in another place", Reference.AppPath), Reference.AppName, MessageBoxButton.OK, MessageBoxImage.Error);
}
// Shutdown
Application.Current.Shutdown();
}
I did a custom message for every exceptions, and it's a little bit long
So i'm waiting for your reviews/advices and thanks a lot i'm still a beginner in that x)