The design and implementation of a poll-type error-handling mechanism

Source: Internet
Author: User
Tags error handling hash
Error | Error handling | Design and implementation of a poll-type error handling mechanism (i.)


--------------------------------------------------------------------------------

Summary

This paper briefly introduces the design idea and implementation of a polling error handling mechanism, which can flexibly realize the extension of error handling mode and the customization of error information format.


--------------------------------------------------------------------------------

Directory

Brief introduction
Class diagram
Description of class and code implementation
How the client is invoked
Summarize
For more information

--------------------------------------------------------------------------------

Brief introduction

Error handling is a fixed module that every application needs to contain. How to design an error-handling mechanism with universal applicability is the core of this paper. This article describes a polling approach that allows users to selectively use defined or user-defined methods for error handling, while allowing users to customize and extend the error message output format.


--------------------------------------------------------------------------------

Class diagram














--------------------------------------------------------------------------------

Description of class and code implementation

Global:



This class is used to enlist error handling and to define its flag value, and there is a global static method numbersplit that converts incoming parameter int x into a string output in binary format. The specific code is as follows:



public class Global

{

Error handling method Count

public const int Error_handle_mode = 5;

Flag values for each type of error handling

public const int None = 0;

public const int debuginfo = 1;

public const int EVENTLOG = 2;

public const int MESSAGEBOX = 4;

public const int LogFile = 8;

public const int Mail = 16;

public const int shortmessage = 32;

public const int Print = 64;

public const int MessageQueue = 128;

public const int Database = 256;

public const int Console = 512;



Public Global ()

{

//

Todo:add constructor Logic here

//

}



public static string Numbersplit (int x)

{

string r = "";

while (x!=0)

{

int t = x%2;

R = t.tostring () + R;

x = X/2;

}

return R;

}

}







Errormsgclass:



The class is an error message containing a class, and any Error object is present as an instance of the class, and an instance of the class is also used as the carrier of the error message throughout the error handling system. The class has only one parameter of the hash type, which holds the specific error message. When this class is instantiated, the error handling is automatically set to 0 (not processed). The specific code is as follows:



public class Errormsgclass

{

Public Hashtable hash= New Hashtable ();



Public Errormsgclass ()

{

//

Error handling defaults to not handling

Hash. ADD ("Mode", 0);

//

}



}





Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.