Bonjour,
J'essaye de faire un petit système de gestion d'erreur dont mes pages pourraient hériter...
J'ai essayé ceci, mais je ne passe jamais par OnThreadException...
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { ExceptionHandler eh = new ExceptionHandler(); Application.ThreadException += new ThreadExceptionEventHandler(eh.OnThreadException); } private void button1_Click(object sender, EventArgs e) { throw new System.ArgumentException("The specified type is unknow", "type"); } } public class ExceptionHandler { public void OnThreadException(object sender, ThreadExceptionEventArgs t) { DialogResult result = DialogResult.Cancel; try { result = this.ShowThreadExceptionDialog(t.Exception); } catch { try { MessageBox.Show("Fatal Error", "Fatal Error", MessageBoxButtons.AbortRetryIgnore, MessageBoxIcon.Stop); } finally { Application.Exit(); } } // Exits the program when the user clicks Abort. if (result == DialogResult.Abort) { Application.Exit(); } } // Creates the error message and displays it. private DialogResult ShowThreadExceptionDialog(Exception e) { string errorMsg = "An error occurred please contact the adminstrator with the following information:\n\n"; errorMsg = errorMsg + e.Message + "\n\nStack Trace:\n" + e.StackTrace; return MessageBox.Show(errorMsg, "Application Error", MessageBoxButtons.AbortRetryIgnore, MessageBoxIcon.Stop); } }
Quelqu'un pourrait m'expliquer ?
Merci.








Répondre avec citation



Pas de questions techniques par MP ! Le forum est là pour ça...
Partager