Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is there Console.Error() in C# but no Console.Warning?

Tags:

c#

.net

In C#, if we want to output an error to the console, we can simply write:

Console.Error.Write("Error!");

But when I try to write a warning to the console, I found that there isn't any:

Console.Warning.Write("Warning!");

Instead, I need to write:

WarningException myEx = new WarningException("This is a warning");
Console.Write(myEx.ToString());

Why is it designed this way?

like image 560
Caesium Avatar asked Aug 09 '18 06:08

Caesium


People also ask

What is the use of console error?

The console. error() method outputs an error message to the Web console.

What is the difference between the console log () and console error () methods?

console. error is used to output error messages while console. log is the most commonly used console method and is used to log out all sorts of objects or messages. In case of some error browser automatically output the relevant error message while you have to manually log out objects using console.

What does the console error property?

What does the Console. Error property do within a console-based application? The Console. Error property gets the standard error output stream.


1 Answers

Because Console is adapting to a much older idiom - where every process has 3 streams associated with it at startup - one standard input stream, one standard output stream, and one standard error stream.

(The standard names here are Console.In, Console.Out and Console.Error are their names in the .NET world, not stdin, stdout & stderr as in C.)

This is no standard warning stream.

Be aware that if you use output redirection when running a console application >file1.txt will redirect the standard output to file1.txt but an error output will continue to be shown on the console. (You use 2>something to redirect the standard error output or 2>&1 to redirect it to the same place that standard output is going to)

like image 53
Damien_The_Unbeliever Avatar answered Sep 30 '22 12:09

Damien_The_Unbeliever