Wednesday, October 31, 2007

Nice way to center HTML element

Just set it's margin css property to "0px auto". Setting "auto" for margin-left and margin-rigth automatically centers elements in all modern browsers except IE5. Here is workaround for IE5.

Wednesday, October 10, 2007

Cute method for logging exceptions

Here is a cute method which returns a string composed of exception (and all its inner exceptions) message and stack trace:


public static String GetExceptionUberStackTrace(Exception e)
{
if (null == e) throw new ArgumentException("Exception parameter shouldn't be null!");
String result = "";

do {
result += String.Format("Message: {0}{1}", e.Message, Environment.NewLine);
result += String.Format(
"Stack trace: {0}{1}{2}",
Environment.NewLine,
e.StackTrace,
Environment.NewLine
);

e = e.InnerException;

if (null != e)
{
result += String.Format("{0}Inner exception:{1}",
Environment.NewLine, Environment.NewLine);
}
else
{
break;
}

} while (true);

return result;
}