553 lines
28 KiB
MQL5
553 lines
28 KiB
MQL5
#ifndef LIB_ERROR_HANDLER_DEFINITIONS_MQH_INCLUDED
|
|
#define LIB_ERROR_HANDLER_DEFINITIONS_MQH_INCLUDED
|
|
#property version "4.0";
|
|
/**********************************************************************************
|
|
* Copyright (C) 2010-2020 Dominik Egert <dominik.egert@freie-netze.de>
|
|
*
|
|
* This file is part of lib_bali
|
|
*
|
|
* lib_error.mqh may be copied and/or distributed at free will
|
|
* Dominik Egert / Freie Netze UG.
|
|
**********************************************************************************
|
|
*
|
|
* Version 4.0
|
|
* State: public
|
|
*
|
|
*
|
|
* File information
|
|
* ================
|
|
*
|
|
* Use: resolve error codes to text
|
|
*
|
|
*
|
|
*
|
|
*/
|
|
|
|
|
|
//*********************************************************************************************************************************************************/
|
|
// Global error handler configuration
|
|
//
|
|
|
|
////////////////////////////////////////////////////
|
|
//
|
|
// Define error group id
|
|
// This ID must be unique within
|
|
// the given project.
|
|
//
|
|
// Valid values for Group ID are
|
|
// between 0x00 and 0xEF
|
|
// 0xF0 to 0xFF is reserved.
|
|
//
|
|
// Error codes categories
|
|
// 0x00 = Succes
|
|
// 0x01 ... 0xDF = Errors,
|
|
// 0xE0 ... 0xEF = Warnings
|
|
// 0xF0 ... 0xFF = Handled Errors
|
|
//
|
|
// Define the size each error
|
|
// router can handle. (0x0100 = 256 here)
|
|
//
|
|
#ifndef LIB_ERR_LEVEL_WARNING
|
|
#define LIB_ERR_LEVEL_WARNING 0x00E0
|
|
|
|
#endif
|
|
#ifndef LIB_ERR_LEVEL_HANDLED_ERROR
|
|
#define LIB_ERR_LEVEL_HANDLED_ERROR 0x00F0
|
|
|
|
#endif
|
|
#ifndef LIB_ERR_INTERNAL_GROUP_IDS
|
|
#define LIB_ERR_INTERNAL_GROUP_IDS 0xF000
|
|
|
|
#endif
|
|
#ifndef LIB_ERR_GROUP_SIZE
|
|
#define LIB_ERR_GROUP_SIZE 0x0100
|
|
|
|
#endif
|
|
|
|
//
|
|
////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////
|
|
//
|
|
// Define error messages
|
|
// output format
|
|
//
|
|
|
|
// Define error output format
|
|
#ifndef LIB_ERR_OUTPUT_FORMAT
|
|
#define LIB_ERR_OUTPUT_FORMAT(_err_code_, _code_name_, _msg_) StringFormat("(%i - %s) %s", _err_code_, _code_name_, _msg_)
|
|
|
|
#endif
|
|
|
|
//
|
|
////////////////////////////////////////////////////
|
|
|
|
|
|
//
|
|
// END Global error handler configuration
|
|
//*********************************************************************************************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
//
|
|
// General setup and error code definition macros
|
|
//
|
|
|
|
|
|
////////////////////////////////////////////////////
|
|
//
|
|
// Maximum possible user error code
|
|
//
|
|
#ifndef ERR_USER_ERROR_LAST
|
|
#define ERR_USER_ERROR_LAST 0xFFFE
|
|
|
|
#endif
|
|
|
|
//
|
|
////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////
|
|
//
|
|
// MQL API defined error codes
|
|
// Additionally, define an MQL5 success code
|
|
//
|
|
#ifndef ERR_SUCCESS
|
|
#define ERR_SUCCESS ERR_NO_ERROR
|
|
|
|
#endif
|
|
//
|
|
/////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////
|
|
//
|
|
// Define library mode
|
|
//
|
|
|
|
// Header mode
|
|
#ifndef LIB_ERR_LIB_EXPORT
|
|
#define LIB_ERR_LIB_EXPORT
|
|
|
|
#endif
|
|
|
|
// Binary mode
|
|
#ifdef LIB_MQLPLUS_BINARY_LIBRARY
|
|
#define LIB_ERR_BINARY_LIBRARY
|
|
|
|
#endif
|
|
#ifdef LIB_ERR_BINARY_LIBRARY
|
|
#ifndef LIB_ERR_NO_INCLUDE
|
|
#define LIB_ERR_NO_INCLUDE
|
|
|
|
#endif
|
|
#ifdef LIB_ERR_LIB_EXPORT
|
|
#undef LIB_ERR_LIB_EXPORT
|
|
|
|
#endif
|
|
#ifdef LIB_DEBUG
|
|
#undef LIB_DEBUG
|
|
|
|
#endif
|
|
#ifdef LIB_ERR_USER_ERROR_HANDLER
|
|
#undef LIB_ERR_USER_ERROR_HANDLER
|
|
|
|
#endif
|
|
#define LIB_ERR_LIB_EXPORT export
|
|
#property library
|
|
|
|
#endif
|
|
|
|
//
|
|
////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////
|
|
//
|
|
// MQL4 compatibility
|
|
//
|
|
|
|
#ifndef __MQL5__
|
|
#ifndef __MQL4_COMPATIBILITY_CODE__
|
|
#define __MQL4_COMPATIBILITY_CODE__
|
|
|
|
#endif
|
|
#define LIB_ERR_NAMESPACE(x, y) x##_##y
|
|
#define LIB_ERR_NAMESPACE_DEF(x, y) LIB_ERR_NAMESPACE(x, y)
|
|
#define LIB_ERR_MT_VERSION_ID_STRING mt4
|
|
|
|
#else
|
|
#define LIB_ERR_NAMESPACE(x, y) x::y
|
|
#define LIB_ERR_NAMESPACE_DEF(x, y) y
|
|
#define LIB_ERR_MT_VERSION_ID_STRING mt5
|
|
|
|
#endif
|
|
|
|
//
|
|
////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////
|
|
//
|
|
// Terminal language IDs
|
|
//
|
|
|
|
#define LIB_ERROR_LANG_FROM_FILE 0x454C4946 // Read error description from file
|
|
#define LIB_ERROR_LANG_TERM_ID_EN 0x6C676E45 // Default language English
|
|
#define LIB_ERROR_LANG_TERM_ID_RU 0x73737552 // Russian
|
|
#ifndef __MQL4_COMPATIBILITY_CODE__
|
|
#define LIB_ERROR_LANG_TERM_ID_ZH 0x6E696843 // Chinese
|
|
#define LIB_ERROR_LANG_TERM_ID_ES 0x6E617053 // Spanish
|
|
#define LIB_ERROR_LANG_TERM_ID_PT 0x74726F50 // Portugese
|
|
#define LIB_ERROR_LANG_TERM_ID_JP 0x6170614A // Japanese
|
|
#define LIB_ERROR_LANG_TERM_ID_DE 0x6D726547 // German
|
|
#define LIB_ERROR_LANG_TERM_ID_KO 0x65726F4B // Korean
|
|
#define LIB_ERROR_LANG_TERM_ID_FR 0x6E657246 // Frensh
|
|
#define LIB_ERROR_LANG_TERM_ID_IT 0x6C617449 // Italian
|
|
#define LIB_ERROR_LANG_TERM_ID_TR 0x6B727554 // Turkish
|
|
|
|
#endif
|
|
|
|
//
|
|
////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
//
|
|
// Custom error code definition macros
|
|
//
|
|
|
|
|
|
////////////////////////////////////////////////////
|
|
//
|
|
// Function name macro substitutions
|
|
//
|
|
|
|
// Select appropiate error handler
|
|
#define OnErrorFunction DefaultOnError
|
|
#ifdef LIB_ERR_USER_ERROR_HANDLER
|
|
#undef OnErrorFunction
|
|
#define OnErrorFunction UserOnError
|
|
|
|
#endif
|
|
|
|
//
|
|
////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////
|
|
//
|
|
// Define error resolver function pointer
|
|
//
|
|
|
|
// User supplied external error resolver function
|
|
typedef const string (*TUsrErrFunc)(const int);
|
|
|
|
//
|
|
////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////
|
|
//
|
|
// Define error register function
|
|
//
|
|
#ifndef __MQL4_COMPATIBILITY_CODE__
|
|
#ifndef LIB_ERR_LIB_IMPORT
|
|
#define lib_err_register_code_resolver LIB_ERR_NAMESPACE(LibError, RegisterErrorCodeResolver)
|
|
|
|
#else
|
|
#define lib_err_register_code_resolver LibError::LIB_ERR_NAMESPACE(LibError, RegisterErrorCodeResolver)
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
//
|
|
////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////
|
|
//
|
|
// User supplied error codes
|
|
//
|
|
|
|
// Helper macro for defining error codes
|
|
#define LIB_ERROR_CODE(x, y) (uint)(((ushort)((ushort)((uchar)(x) * LIB_ERR_GROUP_SIZE) + (uchar)(y)) + ERR_USER_ERROR_FIRST))
|
|
#define LIB_ERROR_CODE_WARNING(x, y) LIB_ERROR_CODE(x, (y + LIB_ERR_LEVEL_WARNING))
|
|
#define LIB_ERROR_CODE_HANDLED(x, y) LIB_ERROR_CODE(x, (y + LIB_ERR_LEVEL_HANDLED_ERROR))
|
|
#define LIB_ERROR_CODE_GROUP_OFFSET(x) (x << 16)
|
|
|
|
// Message resolver helper macros
|
|
#ifndef __MQL4_COMPATIBILITY_CODE__
|
|
#define LIB_ERR_REGISTER_RESOLVER_BEGIN(_id_) namespace lib_err { const string errdesc_##_id_(const int error_code) { switch(error_code) {
|
|
#define LIB_ERR_REGISTER_RESOLVER_END(_id_) }; return(NULL); } const static bool init##_id_ = lib_err_register_code_resolver(_id_, errdesc_##_id_); }
|
|
|
|
#else
|
|
#define LIB_ERR_REGISTER_RESOLVER_BEGIN(_id_) const string lib_err_errdesc_##_id_(const int error_code) { switch(error_code) {
|
|
#define LIB_ERR_REGISTER_RESOLVER_END(_id_) }; return(NULL); } const static bool lib_err_init##_id_ = LIB_ERR_NAMESPACE(LibError, RegisterErrorCodeResolver)(_id_, lib_err_errdesc_##_id_);
|
|
|
|
#endif
|
|
|
|
//
|
|
////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////
|
|
//
|
|
// Reserved error codes
|
|
//
|
|
|
|
// Helper macro for defining reserved error codes
|
|
#define LIB_ERROR_RESERVED_CODE(x, y) (uint)(((ushort)(( (ushort)((uchar)(x) * LIB_ERR_GROUP_SIZE) + (uchar)(y))) + LIB_ERR_INTERNAL_GROUP_IDS + ERR_USER_ERROR_FIRST))
|
|
#define LIB_ERROR_RESERVED_CODE_WARNING(x, y) LIB_ERROR_RESERVED_CODE(x, (y + LIB_ERR_LEVEL_WARNING))
|
|
#define LIB_ERROR_RESERVED_CODE_HANDLED(x, y) LIB_ERROR_RESERVED_CODE(x, (y + LIB_ERR_LEVEL_HANDLED_ERROR))
|
|
#define LIB_ERROR_RESERVED_CODE_GROUP_OFFSET(x) (x << 24)
|
|
|
|
// Message resolver helper macros
|
|
#ifndef __MQL4_COMPATIBILITY_CODE__
|
|
#define LIB_ERR_RESERVED_REGISTER_RESOLVER_BEGIN(_id_) namespace lib_err { const string errdesc_reserved_##_id_(const int error_code) { switch(error_code) {
|
|
#define LIB_ERR_RESERVED_REGISTER_RESOLVER_END(_id_) }; return(NULL); } const static bool init_reserved##_id_ = lib_err_register_code_resolver((LIB_ERR_INTERNAL_GROUP_IDS >> 0x08) + _id_, errdesc_reserved_##_id_); }
|
|
|
|
#else
|
|
#define LIB_ERR_RESERVED_REGISTER_RESOLVER_BEGIN(_id_) const string lib_err_errdesc_reserved_##_id_(const int error_code) { switch(error_code) {
|
|
#define LIB_ERR_RESERVED_REGISTER_RESOLVER_END(_id_) }; return(NULL); } const static bool lib_err_init_reserved##_id_ = LIB_ERR_NAMESPACE(LibError, RegisterErrorCodeResolver)((LIB_ERR_INTERNAL_GROUP_IDS >> 0x08) + _id_, lib_err_errdesc_reserved_##_id_);
|
|
|
|
#endif
|
|
|
|
//
|
|
////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////
|
|
//
|
|
// Error code to text resolver definition
|
|
//
|
|
|
|
#ifndef LIB_ERR_REGISTER_RESOLVER_MSGCODE
|
|
#define LIB_ERR_REGISTER_RESOLVER_MSGCODE(_code_id_, _code_name_, _msg_) case _code_id_: return(LIB_ERR_OUTPUT_FORMAT(error_code, _code_name_, _msg_));
|
|
|
|
#endif
|
|
|
|
//
|
|
////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////
|
|
//
|
|
// Include mql defined error codes and messages
|
|
//
|
|
|
|
// Setup language function macro
|
|
#define LIB_ERROR_LANGUAGE_FUNCTION(_lng_code_) lib_err_code_to_text_##_lng_code_
|
|
|
|
// Include MQL defined error codes
|
|
#ifndef LIB_ERR_NO_INCLUDE
|
|
#ifndef __MQL4_COMPATIBILITY_CODE__
|
|
#ifndef LIB_ERR_LIB_IMPORT
|
|
#include "lib_errtxt_mql5_error_codes.mqh"
|
|
namespace lib_err
|
|
{ #include "lib_errtxt_mql5.mqh" };
|
|
|
|
#endif
|
|
|
|
#else
|
|
#ifndef LIB_ERR_LIB_IMPORT
|
|
#include "lib_errtxt_mql4_error_codes.mqh"
|
|
#include "lib_errtxt_mql4.mqh"
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
//
|
|
////////////////////////////////////////////////////
|
|
|
|
|
|
//
|
|
/////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
//
|
|
// Error handler function import
|
|
//
|
|
|
|
|
|
////////////////////////////////////////////////////
|
|
//
|
|
// Function import / code inclusion
|
|
//
|
|
//
|
|
|
|
#ifdef LIB_ERR_LIB_IMPORT
|
|
#include "lib_error_functions.mqh"
|
|
|
|
#endif
|
|
|
|
#ifndef LIB_ERR_LIB_IMPORT
|
|
#ifndef LIB_ERR_NO_INCLUDE
|
|
#include "lib_error_main.mqh"
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
//
|
|
////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////
|
|
//
|
|
// Custom OnError() handler
|
|
//
|
|
//
|
|
|
|
// Disable user handler in binary library mode
|
|
#ifdef LIB_ERR_BINARY_LIBRARY
|
|
#undef LIB_ERR_USER_ERROR_HANDLER
|
|
|
|
#endif
|
|
|
|
//
|
|
////////////////////////////////////////////////////
|
|
|
|
|
|
//
|
|
/////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
//
|
|
// Error handler function overloads
|
|
//
|
|
// Namespace LibError:: BEGIN
|
|
#ifndef __MQL4_COMPATIBILITY_CODE__
|
|
namespace LibError {
|
|
#ifdef LIB_ERR_LIB_IMPORT
|
|
namespace LibError {
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
//+------------------------------------------------------------------+
|
|
//| OnError() |
|
|
//+------------------------------------------------------------------+
|
|
bool LIB_ERR_NAMESPACE_DEF(LibError, OnErrorFunction)(const int line_no)
|
|
{
|
|
// Local init
|
|
uint err_code = NULL;
|
|
|
|
// Return
|
|
return(LIB_ERR_NAMESPACE(LibError, OnErrorFunction)(err_code, IntegerToString(line_no)));
|
|
}
|
|
|
|
|
|
//+------------------------------------------------------------------+
|
|
//| OnError() |
|
|
//+------------------------------------------------------------------+
|
|
bool LIB_ERR_NAMESPACE_DEF(LibError, OnErrorFunction)(const string prefix = NULL)
|
|
{
|
|
// Local init
|
|
uint err_code = NULL;
|
|
|
|
// Return
|
|
return(LIB_ERR_NAMESPACE(LibError, OnErrorFunction)(err_code, prefix));
|
|
}
|
|
|
|
// Namespace handler
|
|
#ifndef __MQL4_COMPATIBILITY_CODE__
|
|
#ifdef LIB_ERR_LIB_IMPORT
|
|
}; // Namespace LibError::
|
|
|
|
#endif
|
|
}; // Namespace LibError::
|
|
|
|
#endif
|
|
|
|
|
|
//+------------------------------------------------------------------+
|
|
//| OnError() |
|
|
//+------------------------------------------------------------------+
|
|
#ifndef LIB_ERR_USER_ERROR_HANDLER
|
|
#ifdef LIB_ERR_LIB_IMPORT
|
|
#ifdef __MQL4_COMPATIBILITY_CODE__
|
|
#import "Shared Projects/LibError/LibError.ex4"
|
|
|
|
#else
|
|
#import "Shared Projects/LibError/LibError.ex5"
|
|
namespace LibError
|
|
{
|
|
|
|
#endif
|
|
|
|
const bool LIB_ERR_NAMESPACE_DEF(LibError, OnErrorFunction)(uint& err_no, const string prefix = NULL);
|
|
|
|
#ifndef __MQL4_COMPATIBILITY_CODE__
|
|
}; // Namespace LibError::
|
|
|
|
#endif
|
|
#import
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
//
|
|
/////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
/**************************************/
|
|
#endif // LIB_ERROR_HANDLER_DEFINITIONS_MQH_INCLUDED
|