Exception Handler

07/12/2011 21:52 BaussHacker#1
So I'm trying to make my own source from scratch and I was thinking if an exception handler would be a good thing to have? Instead having to change every try/catch when catching exceptions.

Using this AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(Handle); from Hybrids source thought.

What I have done is:
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ConquerServerProject.FileHandler;

namespace ConquerServerProject.Core
{
    public class ExceptionHandler
    {
        public static bool GlobalUnhandledError = false;
        FileLog ExceptionLog;

        public ExceptionHandler()
        {
            AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(Handle);

#if EXCEPTION_LOG
                ExceptionLog = new FileLog("exceptionlog.txt");
                ExceptionLog.Open();
#endif
        }

        private void Handle(object sender, UnhandledExceptionEventArgs e)
        {
            FileLog GlobalExceptionLog = new FileLog("globalexceptions.txt");
            GlobalExceptionLog.Open();
            GlobalExceptionLog.Write("[Global Exception - " + DateTime.Now + "]");
            GlobalExceptionLog.Write("Exception:\n" + e.ToString());
            GlobalExceptionLog.End();

            GlobalUnhandledError = true;
        }
        public void Handle(Exception exception)
        {
            Console.ForegroundColor = ConsoleColor.Red;
            Console.WriteLine(exception.ToString());
            Console.ResetColor();

#if EXCEPTION_LOG
                ExceptionLog.Write("[Exception - " + DateTime.Now + "]");
                ExceptionLog.Write("Exception:\n" + exception.ToString());            
                if (exception.InnerException != null)
                {
                    ExceptionLog.Write("\nInner Exception:\n" + exception.InnerException.ToString());
                }  
#endif
        }
    }
}
Would this do any difference? :)
07/12/2011 21:54 _DreadNought_#2
I'm always on msn bro
<3

#edit

As I told you on msn, That wouldnt be a good idea when for example you have the code
Code:
static void GrabBiggestCocks(string Bob)
{
   try
   {
      Socket.Send(PornHub.ToAddress + Bob);
   }
   catch
   {
      Socket.Disconnect();
      Exception.Throw(Error);
   }
}
In alot of cases, Try{} catch{} methods are good because you can take action like saving then disconnecting a client to stop any fatal errors happening/continueing AND reports an exception.

So like, You would do those try's and catch's etc because of that exception handler, but what if you want to report the exception and disconnect the socket on a thrown exception, You cant without those or extremely long inefficient programming.

To sum it up:
It wouldnt be efficient if you want to take different actions depending on the context of the exception being thrown.