So let me get it straight..should the custom exception class be inside the DLL ? or in the GUI itself ? (the DLL is not sealed).
Plus - I have another problem.
one of my classes in the DLL is reading an XML file.
I want the user to be displayed with a generic "XML Parsing Error" message - nothing more than that.
if in the GUI I have the following code :
try
{
ReadXmlFunction()
}
catch(CustomExceptionClass ex)
{
}
and in the ReadXmlFunction() - an xmlException will be thrown - the catch block won't catch it - why is that ?
The custom exception class that I wrote looks like this :
public class CustomException : Exception
{
enum Type { SqlException, XmlException, Exception,Custom };
Type ExceptionType;
public CustomException(Exception ex):base()
{
switch (ex.GetType().ToString())
{
case "SqlException":
ExceptionType = Type.SqlException;
break;
case "XmlException":
ExceptionType = Type.XmlException;
break;
default:
ExceptionType = Type.Exception;
break;
}
}
public CustomException(string detail):base(detail)
{
ExceptionType = Type.Custom;
}
public string GetErrorDescription()
{
switch (ExceptionType)
{
case Type.SqlException:
return String.Format("DB Error - {0}\nError Serial # : {1}", ((SqlException)(this.GetBaseException())).Message, ((SqlException)(this.GetBaseException())).Number);
case Type.XmlException:
return String.Format("XML Parsing Error - {0}", ((System.Xml.XmlException)(this.GetBaseException() )).Message);
case Type.Exception:
return String.Format("Unrecognized General Error - {0}", Message);
case Type.Custom:
return String.Format("Reporting System Error - {0}", Message);
}
return "Critical Error recognition error. Error is : " + Message;
}
}
Thanks in advance.