So, i have a problem with my C# project. Let's say i have a lot of errors in different classes. And i don't want to try & catch them all. How could i catch an exception anywhere, and show a MessageBox with the message of the exception?
Example:
class Program {
static void Main(string[] args) {
DifferentFile.Execute();
}
}
class DifferentFile {
public static PictureBox blabla = null;
public static void Execute() {
blabla.Image = Resources.SomeImage; // Random code with the picturebox
}
}
This should throw an exception (This is example code so idk but probably). How could i catch all exceptions in the WHOLE application with a MessageBox (System.Windows.Forms) if i have multiple classes.
(Like this)
try {
// Code
} catch (Exception ex) {
MessageBox.Show("Exception thrown:\r\n\r\n" + ex.Message); // Or ex.Stacktrace
}
Also, sorry if anything is wrong or if there is like lack of whatever (Confusing). Please just ask.