C# 0 The Complete Reference


Console.Out  and  Console.Error



Download 4,07 Mb.
Pdf ko'rish
bet481/1096
Sana23.01.2022
Hajmi4,07 Mb.
#402171
1   ...   477   478   479   480   481   482   483   484   ...   1096
Bog'liq
C-Sharp 3 The Complete Reference Herbert Schildt

Console.Out

 and 


Console.Error

. By 


default, both write to the console.

// Write to Console.Out and Console.Error.

using System;

class ErrOut {

  static void Main() {

    int a=10, b=0;

    int result;

    Console.Out.WriteLine("This will generate an exception.");

    try {

      result = a / b; // generate an exception

    } catch(DivideByZeroException exc) {

      Console.Error.WriteLine(exc.Message);

    }

  }


}

The output from the program is shown here:

This will generate an exception.

Attempted to divide by zero.

Sometimes newcomers to programming are confused about when to use 

Console.Error

.

Since both 



Console.Out

 and 


Console.Error

 default to writing their output to the console, 

why are there two different streams? The answer lies in the fact that the standard streams 

can be redirected to other devices. For example, 



Console.Error

 can be redirected to write to 

a disk file, rather than the screen. Thus, it is possible to direct error output to a log file, for 

example, without affecting console output. Conversely, if console output is redirected and 

error output is not, then error messages will appear on the console, where they can be seen. 

We will examine redirection later, after file I/O has been described.




Download 4,07 Mb.

Do'stlaringiz bilan baham:
1   ...   477   478   479   480   481   482   483   484   ...   1096




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish