Write to Console.Out and Console.Error : Console Output : Development C# Examples


C# Examples » Development » Console Output »

 

Write to Console.Out and Console.Error









    
using  System;  
  
class  MainClass  {  
    public  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);  
        }  
    }  
}
    
   
  
   



Output

This will generate an exception.
Attempted to divide by zero.


HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo Development
» Console Output