473,395 Members | 1,571 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Viewing Exception Details

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.
Nov 19 '08 #1
1 9371
Well, if you want to show the details, and this is what you want to see,
then by all means, use it. I'd probably move the call to MessageBox.Show
into the method as well (save some typing) and call it something else (like
DisplayDetails).

However, if you want to use this for other purposes (like logging to a
file) then it is just fine the way it is (although there are other logging
mechanisms out there).
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

<Ma*************@gmail.comwrote in message
news:08**********************************@35g2000p ry.googlegroups.com...
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.
Nov 19 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Mita | last post by:
I Am trying to post my form on to a second page, but it keeps coming with a, error: Exception Details: System.Web.HttpException: The View State is invalid for this page and might be corrupted. ...
2
by: Bill Nguyen | last post by:
I got this error emssage trying to run an ASP.NET application on my Win2003/IIS6.0 server: Exception Details: System.UnauthorizedAccessException: Access to the path...
6
by: Tony | last post by:
Dear All, When I run an example program on the http://www.dotnetjunkies.com/quickstart/util/srcview.aspx?path=/quickstart/aspplus/samples/webforms/data/datagrid1.src&file=VB\datagrid1.aspx&font=3 ...
0
by: silesius | last post by:
I've been using VS.NET 2003 to develop a webapplication using C#. Today I exported the application to another webserver I begun experiencing problems. It's a simple application that retrieves...
0
by: masago | last post by:
Hi....how are you ?? they can help me to solve this problem ?? Access to the path = "c:\windows\microsoft.net\framework\v1.1.4322\Temporary ASP.NET = Files\reports\06639073\bbab30a7" is...
1
by: differentsri | last post by:
THIS IS AN ASP.NET 1.1 APPLICATION IAM TRYING TO UPDATE THE FIELD BUT I AM NOT ABLE TO UPDATE IT? CAN U TELL THE REASON ? IT IS GIVING THE FOLLOWING ERROR BELOW I HAVE ALSO GIVEN THE CODE OF...
2
by: itsvineeth209 | last post by:
Object reference not set to an instance of an object. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more...
4
by: minhtran | last post by:
Hi All I create web page as ASP.NET . The program runs on localhost no problem,but when we upload on server has an error as : An unhandled exception occurred during the execution of the current web...
3
by: Lee Cripps | last post by:
Hi, Not sure if my question belongs in an ASP.NET or MSSQL forum.. I have an ASP.NET webpage built in VS2010 with an Input field with the functionality to browse to a network directory, select...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.