How can I make my console program or service to:
Console.Beep()
on every single exception? Edit 1: As I am working on legacy code which contains hundreds of exceptions already, adding Console.Beep()
in every single of them is not an option and on top of that it's also not easily maintainable, taking into consideration the plethora of the existing exceptions.
Well, simply you can put the code you expect to throw an exception in a try catch block like this:
try
{
// your code here
}
catch (Exception) // this goes to every single exception, if you want to beep on a specific one just replace the Exception with the exception you expect e.g NullReferenceException
{
Console.Beep();
throw;
}
If you do not want to see the exception when it occurs, just remove the throw statement from the catch block.