I have a WeekdayException class that has the ToString(). I want to return the string set up in Constructor ("Illegal weekday: " + wday) with ToString(). How to access the string?
using System;
class WeekdayException : ApplicationException {
public WeekdayException(String wday) : base("Illegal weekday: " + wday) {}
public override string ToString()
{
return "HELLO" + ???;
}
}
class TryCatchFinally
{
public static void Main(String[] args)
{
try
{
throw new WeekdayException("thrown by try");
}
catch (ApplicationException ex)
{
Console.WriteLine("Catch ..." + ex.ToString());
}
}
}
And is this (making and using ToString()) the method that C# programmers use? If not, what's the way to go?
ApplicationExceptionhas been dis-recommended for quite some time. Inherit directly fromException.