How can I redirect Unhandled Exceptions from Standart Output or Error Stream to other Streams

Viewed 20
Console.SetIn(new StreamReader(new FileStream("C:/Users/User/Desktop/Testing/RedirectIn.txt", FileMode.OpenOrCreate,
                           FileAccess.ReadWrite, FileShare.None, 128, FileOptions.None), Encoding.UTF8, true, 8, false));

        Console.SetOut(new StreamWriter(new FileStream("C:/Users/User/Desktop/Testing/RedirectOut.txt", FileMode.Truncate), Encoding.UTF8, 2));

        Console.SetError(new StreamWriter(new FileStream("C:/Users/User/Desktop/Testing/RedirectError.txt", FileMode.Truncate), Encoding.UTF8, 2));

So I have Set the In Out and Error Streams
But let's say I erite this snippet and I do not catch the exception.

int y = 5;

Console.Error.WriteLine(y / 0);
//or
Console.WriteLine(y / 0);

The unhandled exception still gets displayed in my Console window but not in my specified error and Out TextWriters.

Can you please tell me why is that so and how can I make unhandled exceptions information be written not in the console but not in my specified error and Out TextWriters?

0 Answers
Related