C# Possible to have a generic return type?
<p>Here is a typical function that returns either true/false;</p>

<pre><code>private static bool hasValue()
{
    return true; 
}
</code></pre>

<p>Now on an error, I would like to return my own custom error object with definition:</p>

<pre><code>public class Failure
    {
        public string FailureDateTime { get; set; }
        public string FailureReason { get; set; }
    }
</code></pre>

<p>I would have expected to be able to throw this custom object for example...</p>

<pre><code>private static bool hasValue()
{
    try
        {
           ...do something
        }
    catch 
        {
         throw new Failure();
         }
    return true; 
}
</code></pre>

<p>This is not possible, and I don't want to derive Failure from System.IO.Exception because I have personally had issues serializing exceptions in C# (This was with .net v2). </p>

<p>What is the best practice / or ideal solution to this problem. Should I just work with private static object? Or is there a cleaner way to return a custom object or bypass the typical return type on an error (not using System.IO.Exception)?</p>

<p>I am not entirely wild about using an object either, because then I need to validate the result by using casting and more boolean.</p>
