I am not sure if this is at all possible. (I think it should). Would it be possible to catch a customexception without throwing new one as follows?
try
{
//Some logic which throws exception
}
catch (Exception)
{
throw new CustomException();
}
What I would like to have is as follows:
try
{
//Some logic which throws exception
}
catch (CustomException)
{
// Handles the exception
}
I have tried the above but its not catching my CustomException directly. I have to do "throw new CustomException()
" which is not ideal. What am I doing wrong?
My custom exception class looks like as follows:
[Serializable]
public class CustomException : Exception
{
public CustomException()
: base() { }
public CustomException(string message)
: base(message) { }
public CustomException(string format, params object[] args)
: base(string.Format(format, args)) { }
public CustomException(string message, Exception innerException)
: base(message, innerException) { }
public CustomException(string format, Exception innerException, params object[] args)
: base(string.Format(format, args), innerException) { }
protected CustomException(SerializationInfo info, StreamingContext context)
: base(info, context) { }
}
Thanks,