Showing posts with label Debugging. Show all posts
Showing posts with label Debugging. Show all posts

Tuesday, June 8, 2010

Exception.ToString() vs. Exception.Message

ToString is superior than Message. Very useful for debugging purposes!


using System;
using System.Collections.Generic;
using System.Text;


namespace ExceptionToString
{
    public class MyClass {}


    public class ArgExceptionExample 
    {
        static void Main(string[] args)
        {
            MyClass my = new MyClass();
            string s = "sometext";


            try 
            {
                int i = s.CompareTo(my);
            }
            catch (Exception ex) 
            {
                Console.WriteLine("Error: {0}\n", ex.ToString());
                Console.WriteLine("Error: {0}", ex.Message);


                Console.Read();
            }
        }
    }
}