M
Magnus.Moraberg
Hi,
Is it a code practice for me to have writen the following Class? -
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.Collections;
namespace mine
{
static class ExceptionDetails
{
static public string Details(Exception exception)
{
string exceptionString = "";
try
{
int i = 0;
while (exception != null)
{
exceptionString += "*** Exception Level " + i + "
***\n";
exceptionString += "Message: " + exception.Message
+ "\n";
exceptionString += "Source: " + exception.Source +
"\n";
exceptionString += "Target Site: " +
exception.TargetSite + "\n";
exceptionString += "Stack Trace: " +
exception.StackTrace + "\n";
exceptionString += "Data: ";
foreach (DictionaryEntry keyValuePair in
exception.Data)
exceptionString += keyValuePair.Key.ToString()
+ ":" + keyValuePair.Value.ToString();
exceptionString += "\n***\n\n";
exception = exception.InnerException;
i++;
}
}
catch{}
return exceptionString;
}
}
}
I then use it as follows -
try
{
...
}
catch (Exception exception)
{
MessageBox.Show(ExceptionDetails.Details(exception), "Error.");
}
Thanks,
Barry.
Is it a code practice for me to have writen the following Class? -
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.Collections;
namespace mine
{
static class ExceptionDetails
{
static public string Details(Exception exception)
{
string exceptionString = "";
try
{
int i = 0;
while (exception != null)
{
exceptionString += "*** Exception Level " + i + "
***\n";
exceptionString += "Message: " + exception.Message
+ "\n";
exceptionString += "Source: " + exception.Source +
"\n";
exceptionString += "Target Site: " +
exception.TargetSite + "\n";
exceptionString += "Stack Trace: " +
exception.StackTrace + "\n";
exceptionString += "Data: ";
foreach (DictionaryEntry keyValuePair in
exception.Data)
exceptionString += keyValuePair.Key.ToString()
+ ":" + keyValuePair.Value.ToString();
exceptionString += "\n***\n\n";
exception = exception.InnerException;
i++;
}
}
catch{}
return exceptionString;
}
}
}
I then use it as follows -
try
{
...
}
catch (Exception exception)
{
MessageBox.Show(ExceptionDetails.Details(exception), "Error.");
}
Thanks,
Barry.