Export (0) Print
Expand All

Console.Error Property

Gets the standard error output stream.

Namespace: System
Assembly: mscorlib (in mscorlib.dll)

public static TextWriter Error { get; }
/** @property */
public static TextWriter get_Error ()

public static function get Error () : TextWriter

Not applicable.

Property Value

A TextWriter that represents the standard error output stream.

This property is set to the standard error stream by default. This property can be set to another stream with the SetError method.

The following code example illustrates the use of the Error property.

public class ExpandTabs {
    private const int tabSize = 4;
    private const string usageText = "Usage: EXPANDTABSEX inputfile.txt outputfile.txt";
    public static int Main(string[] args) {
        StreamWriter writer = null;
        TextWriter standardOutput = Console.Out;

        if (args.Length < 2) {
            Console.WriteLine(usageText);
            return 1;
        }

        try {
            writer = new StreamWriter(args[1]);
            Console.SetOut(writer);
            Console.SetIn(new StreamReader(args[0]));
        }
        catch(IOException e) {
            TextWriter errorWriter = Console.Error;
            errorWriter.WriteLine(e.Message);
            errorWriter.WriteLine(usageText);
            return 1;            
        }
        int i;
        while ((i = Console.Read()) != -1) {
            char c = (char)i;
            if (c == '\t')
                Console.Write(("").PadRight(tabSize, ' '));
            else
                Console.Write(c);
        }
        writer.Close();
        // Recover the standard output stream so that a 
        // completion message can be displayed.
        Console.SetOut(standardOutput);
        Console.WriteLine("EXPANDTABSEX has completed the processing of {0}.", args[0]);
        return 0;
    }
}

public class ExpandTabs
{
    private static int tabSize = 4;
    private static String usageText =
        "Usage: EXPANDTABSEX inputfile.txt outputfile.txt";
    public static void main(String[] args)
    {
        StreamWriter writer = null;
        TextWriter standardOutput = Console.get_Out();
        if (args.length < 2) {
            Console.WriteLine(usageText);
            return;
        }
        try {
            writer = new StreamWriter(args[1]);
            Console.SetOut(writer);
            Console.SetIn(new StreamReader(args[0]));
        }
        catch (IOException e) {
            TextWriter errorWriter = Console.get_Error();
            errorWriter.WriteLine(e.get_Message());
            errorWriter.WriteLine(usageText);
            return;
        }
        int i;
        while (((i = Console.Read()) != -1)) {
            char c = (char)(i);
            if (c == '\t') {
                Console.Write("".PadRight(tabSize, ' '));
            }
            else {
                Console.Write(c);
            }
        }
        writer.Close();
        // Recover the standard output stream so that a 
        // completion message can be displayed.
        Console.SetOut(standardOutput);
        Console.WriteLine("EXPANDTABSEX has completed the processing of {0}.",
            args[0]);
        return;
    } //main
} //ExpandTabs

public class ExpandTabs {
    private static var tabSize : int = 4;
    private static var usageText : String  = "Usage: EXPANDTABSEX inputfile.txt outputfile.txt";
    public static function Main(args : String[]) : int {
        var writer : StreamWriter = null;
        var standardOutput : TextWriter = Console.Out;

        if (args.Length < 2) {
            Console.WriteLine(usageText);
            return 1;
        }

        try {
            writer = new StreamWriter(args[1]);
            Console.SetOut(writer);
            Console.SetIn(new StreamReader(args[0]));
        }
        catch(e : IOException) {
            var errorWriter : TextWriter = Console.Error;
            errorWriter.WriteLine(e.Message);
            errorWriter.WriteLine(usageText);
            return 1;            
        }
        var i : int;
        while ((i = Console.Read()) != -1) {
            var c : char = char(i);
            if (c == '\t')
                Console.Write(("").PadRight(tabSize, ' '));
            else
                Console.Write(c);
        }
        writer.Close();
        // Recover the standard output stream so that a 
        // completion message can be displayed.
        Console.SetOut(standardOutput);
        Console.WriteLine("EXPANDTABSEX has completed the processing of {0}.", args[0]);
        return 0;
    }
}

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0

XNA Framework

Supported in: 1.0

Community Additions

ADD
Show:
© 2014 Microsoft