port from perforce
This commit is contained in:
121
aiwaz/Aiwaz.Core/Exception.cs
Normal file
121
aiwaz/Aiwaz.Core/Exception.cs
Normal file
@@ -0,0 +1,121 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace Aiwaz.Core
|
||||
{
|
||||
public class InitializingFailedException : Exception
|
||||
{
|
||||
public InitializingFailedException()
|
||||
: this(null, null)
|
||||
{
|
||||
}
|
||||
|
||||
public InitializingFailedException(string objectName)
|
||||
: this(objectName, null)
|
||||
{
|
||||
}
|
||||
|
||||
public InitializingFailedException(string objectName, string reason)
|
||||
{
|
||||
string text = "";
|
||||
if (string.IsNullOrEmpty(objectName) && string.IsNullOrEmpty(reason))
|
||||
text = "Unable to initialize object.";
|
||||
else if (string.IsNullOrEmpty(reason))
|
||||
text = string.Format("Unable to initialize object '{0}'.", objectName);
|
||||
else if (string.IsNullOrEmpty(objectName))
|
||||
text = string.Format("Unable to initialize object. {0}", reason);
|
||||
else
|
||||
text = string.Format("Unable to initialize object '{0}'. {1}", objectName, reason);
|
||||
|
||||
if (string.IsNullOrEmpty(text))
|
||||
{
|
||||
Console.ForegroundColor = ConsoleColor.Red;
|
||||
Console.WriteLine(text);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class UninitializingFailedException : Exception
|
||||
{
|
||||
public UninitializingFailedException()
|
||||
: this(null, null)
|
||||
{
|
||||
}
|
||||
|
||||
public UninitializingFailedException(string objectName)
|
||||
: this(objectName, null)
|
||||
{
|
||||
}
|
||||
|
||||
public UninitializingFailedException(string objectName, string reason)
|
||||
{
|
||||
string text = "";
|
||||
if (string.IsNullOrEmpty(objectName) && string.IsNullOrEmpty(reason))
|
||||
text = "Unable to uninitialize object.";
|
||||
else if (string.IsNullOrEmpty(reason))
|
||||
text = string.Format("Unable to uninitialize object '{0}'.", objectName);
|
||||
else if (string.IsNullOrEmpty(objectName))
|
||||
text = string.Format("Unable to uninitialize object. {0}", reason);
|
||||
else
|
||||
text = string.Format("Unable to uninitialize object '{0}'. {1}", objectName, reason);
|
||||
|
||||
if (string.IsNullOrEmpty(text))
|
||||
{
|
||||
Console.ForegroundColor = ConsoleColor.Red;
|
||||
Console.WriteLine(text);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class OnlyOneInstanceAllowedException : Exception
|
||||
{
|
||||
public OnlyOneInstanceAllowedException()
|
||||
: this(null, null)
|
||||
{
|
||||
}
|
||||
|
||||
public OnlyOneInstanceAllowedException(string objectName)
|
||||
: this(objectName, null)
|
||||
{
|
||||
}
|
||||
|
||||
public OnlyOneInstanceAllowedException(string objectName, string reason)
|
||||
{
|
||||
string text = "";
|
||||
if (string.IsNullOrEmpty(objectName) && string.IsNullOrEmpty(reason))
|
||||
text = "Only one instance of this object could exist.";
|
||||
else if (string.IsNullOrEmpty(reason))
|
||||
text = string.Format("Only one instance of this object '{0}' could exist.", objectName);
|
||||
else if (string.IsNullOrEmpty(objectName))
|
||||
text = string.Format("Only one instance of this object could exist. {1}", reason);
|
||||
else
|
||||
text = string.Format("Only one instance of this object '{0}' could exist. {1}", objectName, reason);
|
||||
|
||||
if (string.IsNullOrEmpty(text))
|
||||
{
|
||||
Console.ForegroundColor = ConsoleColor.Red;
|
||||
Console.WriteLine(text);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class ActionFailedException : Exception
|
||||
{
|
||||
public ActionFailedException()
|
||||
: this("Action has failed.")
|
||||
{
|
||||
}
|
||||
|
||||
public ActionFailedException(string text)
|
||||
: base(text)
|
||||
{
|
||||
if (string.IsNullOrEmpty(text))
|
||||
{
|
||||
Console.ForegroundColor = ConsoleColor.Red;
|
||||
Console.WriteLine(text);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user