Results 1 to 7 of 7

Thread: Object to System.Exception [RESOLVED]

  1. #1

    Thread Starter
    KrisSiegel.com Kasracer's Avatar
    Join Date
    Jul 2003
    Location
    USA, Maryland
    Posts
    4,985

    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.

  2. #2

  3. #3

    Thread Starter
    KrisSiegel.com Kasracer's Avatar
    Join Date
    Jul 2003
    Location
    USA, Maryland
    Posts
    4,985
    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.

  4. #4
    Frenzied Member
    Join Date
    Aug 2000
    Posts
    1,539
    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.

  5. #5

    Thread Starter
    KrisSiegel.com Kasracer's Avatar
    Join Date
    Jul 2003
    Location
    USA, Maryland
    Posts
    4,985
    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.

  6. #6
    Hyperactive Member
    Join Date
    Aug 2002
    Location
    Fort Collins, CO
    Posts
    366
    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();
            }
        }


  7. #7

    Thread Starter
    KrisSiegel.com Kasracer's Avatar
    Join Date
    Jul 2003
    Location
    USA, Maryland
    Posts
    4,985
    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
  •  



Click Here to Expand Forum to Full Width