Normally a .NET console application writes its exception messages directly to the console so that the user can view them.
Here’s an example:
static void Main(string[] args)
{
RunStandardErrorRedirectExample();
Console.ReadKey();
}
private static void RunStandardErrorRedirectExample()
{
try
{
double res = Divide(100, 0);
Console.WriteLine(res);
}
catch (Exception ex)
{
using (TextWriter errorWriter = Console.Error)
{
errorWriter.WriteLine(ex.Message);
}
}
}
private static double Divide(int divideWhat, int divideBy)
{
return divideWhat / divideBy;
}
You’ll get “Attempted to divide by 0” in the console.
However, this is not the only option you have. The standard error output channel can be overridden.
Read more of this post