Register for your free account! | Forgot your password?

You last visited: Today at 12:37

  • Please register to post and access all features, it's quick, easy and FREE!

Advertisement



Exception Handler

Discussion on Exception Handler within the CO2 Private Server forum part of the Conquer Online 2 category.

Reply
 
Old   #1
 
elite*gold: 0
Join Date: May 2011
Posts: 1,769
Received Thanks: 756
Exception Handler

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?
BaussHacker is offline  
Old 07/12/2011, 21:54   #2
 
_DreadNought_'s Avatar
 
elite*gold: 28
Join Date: Jun 2010
Posts: 2,225
Received Thanks: 868
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.
_DreadNought_ is offline  
Thanks
2 Users
Reply


Similar Threads Similar Threads
about firewall exception
05/04/2011 - Grand Chase Philippines - 3 Replies
question lng po.. if nakacheck ung box sa firewall exception ng grand chase meaning ba nun exception na sya sa firewall? sorry po sa wrong thread...
Wierd exception
03/24/2011 - CO2 Private Server - 2 Replies
#Removed the content, since it was a pretty long page. If you really want to know it find an archive online or just ask.
K2 Exception
01/15/2010 - Heroes of Newerth - 0 Replies
How can i solve that error? Help me pls
can anyone help with this unhandled exception?
03/21/2006 - Silkroad Online - 4 Replies
sro_client.exe(2160) - Unhandled Exception ACCESS_VIOLATION (0xc0000005) at address 0x10034a24 in module C:&#092;Documents and Settings&#092;user&#092;Desktop&#092;s robot&#092;Silk.dll(2006-03-19:10-10-54). Registers: EAX 00000028 EBX 0000000A ECX 10929118 EDX 0012FC56 ESI 0012FC50 EDI 10929118 CS:EIP 0000001B:10034A24 SS:ESP 00000023:0012FBF8 EBP 00000023 C:&#092;Documents and Settings&#092;user&#092;Desktop&#092;s robot&#092;Silk.dll at address: 10034a24 the sro_client.exe is 1,815,552 bytes



All times are GMT +1. The time now is 12:39.


Powered by vBulletin®
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Support | Contact Us | FAQ | Advertising | Privacy Policy | Terms of Service | Abuse
Copyright ©2025 elitepvpers All Rights Reserved.