|
-
Jan 6th, 2004, 02:57 PM
#1
Object to System.Exception [RESOLVED]
I need a dynamic array, so I am using an ArrayList, however, I need it to contain Exceptions. I can add Exceptions to it fine, however, using them and trying to return just 1 of them (i.e. return ArrayList1[0]) is a problem.
When I add an Exception to the ArrayList, it converts it to an Object and once it puts it inside of the list, I cannot use it as an Exceptions anymore.
Is there a way to hold Exceptions in a dynamic array? Regular arrays with a set max just don't seem to work for some reason.
Also, is there a way to capture ALL Exceptions that happen within a program? Like some sort of an event? Or am I going to have to encapsulate everything in try/catch statements?
Incase you haven't noticed, I'm trying to write a self-contained DLL file in which writes the user's computer information to a log file, then on close, ALL exception information that happens with my program is also written to the log file. Later I'm gonna make a dialogbox out of just code to ask the user if they want to send it directly to me. This would make it alot easier to track errors on computers once it leaves the development environment.
Last edited by Kasracer; Jan 6th, 2004 at 11:08 PM.
-
Jan 6th, 2004, 10:14 PM
#2
PowerPoster
-
Jan 6th, 2004, 10:37 PM
#3
The class I already got made-up somewhat does just what I want on exit, and I know what I want it to do (ApplicationBlocks would require alot more work and this can be simple plug and play), but thanks anyway.
-
Jan 6th, 2004, 10:50 PM
#4
Frenzied Member
why invent something for something that it wasnt invented for
use ApplicationBlock for this and you will have less headaches down the road.
Brian, very good find.
Last edited by kovan; Jan 6th, 2004 at 11:00 PM.
-
Jan 6th, 2004, 11:08 PM
#5
Originally posted by kovan
why invent something for something that it wasnt invented for
Uh?
Originally posted by kovan
use ApplicationBlock for this and you will have less headaches down the road.
But the code I already have will fit nicely in my program's current code already.
I think I'm done with this thread though, I found a better way to do some of my logging than with an array.
-
Jan 7th, 2004, 01:24 AM
#6
Hyperactive Member
Well, for what it's worth, when you save any object to an arraylist, true, it's saved as an object but it still knows what type it was previous to being added to the list. So just cast it back to the original type.
PHP Code:
using System;
using System.Collections;
namespace ExceptionArrayList
{
public class MainApp
{
public static void Main(string[] args)
{
ArrayList exceptionList = new ArrayList();
try
{
throw new Exception("Whatever");
}
catch(Exception ex)
{
exceptionList.Add(ex);
}
Exception myException = (Exception)exceptionList[0];
Console.WriteLine(myException.Message);
Console.ReadLine();
}
}
}
-
Jan 7th, 2004, 02:34 AM
#7
Thanks, that might come in handy
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|