@@ -13,6 +13,23 @@ internal partial class LicenseForm : Form
13
13
/// </summary>
14
14
private static readonly Logger Logger = LogManager . GetCurrentClassLogger ( ) ;
15
15
16
+ /// <summary>
17
+ /// Handles exceptions by logging the error and showing a message box.
18
+ /// </summary>
19
+ /// <param name="ex">The exception that occurred.</param>
20
+ /// <param name="message">The message to log and display.</param>
21
+ /// <param name="sender">The source of the event that caused the exception.</param>
22
+ /// <param name="e">The event data associated with the exception.</param>
23
+ private static void HandleException ( Exception ex , string message , object ? sender = null , EventArgs ? e = null )
24
+ {
25
+ // Implement logging logic here (e.g., log to a file or monitoring system)
26
+ string msg = $ "Error: { ex } \n Message: { ex . Message } \n StackTrack: { ex . StackTrace } \n Sender: { sender } , EventArgs: { e } ";
27
+ Debug . WriteLine ( value : msg ) ;
28
+ Console . WriteLine ( value : msg ) ;
29
+ Logger . Error ( exception : ex , message : msg ) ;
30
+ _ = MessageBox . Show ( text : message , caption : "Error" , buttons : MessageBoxButtons . OK , icon : MessageBoxIcon . Error ) ;
31
+ }
32
+
16
33
/// <summary>
17
34
/// Set a specific text to the status bar
18
35
/// </summary>
@@ -30,18 +47,6 @@ private void SetStatusbarText(string text)
30
47
}
31
48
}
32
49
33
- /// <summary>
34
- /// Handles exceptions by logging the error and showing a message box.
35
- /// </summary>
36
- /// <param name="ex">The exception that occurred.</param>
37
- /// <param name="message">The message to log and display.</param>
38
- private static void HandleException ( Exception ex , string message )
39
- {
40
- Debug . WriteLine ( value : ex ) ;
41
- Logger . Error ( exception : ex , message : message ) ;
42
- _ = MessageBox . Show ( text : message , caption : "Error" , buttons : MessageBoxButtons . OK , icon : MessageBoxIcon . Error ) ;
43
- }
44
-
45
50
/// <summary>
46
51
/// Constructor
47
52
/// </summary>
@@ -113,7 +118,7 @@ private void SetStatusbar_Enter(object sender, EventArgs e)
113
118
}
114
119
catch ( Exception ex )
115
120
{
116
- HandleException ( ex : ex , message : "An error occurred while setting the status bar text." ) ;
121
+ HandleException ( ex : ex , message : "An error occurred while setting the status bar text." , sender : sender , e : e ) ;
117
122
}
118
123
}
119
124
@@ -151,7 +156,7 @@ private void LicenseForm_KeyDown(object? sender, KeyEventArgs e)
151
156
}
152
157
catch ( Exception ex )
153
158
{
154
- HandleException ( ex : ex , message : "An error occurred while handling the KeyDown event." ) ;
159
+ HandleException ( ex : ex , message : "An error occurred while setting the status bar text." , sender : sender , e : e ) ;
155
160
}
156
161
}
157
162
}
0 commit comments