Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3236556
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T17:38:08+00:00 2026-05-17T17:38:08+00:00

I wrote this interface: //The idea is to use EHPrint to construct the error

  • 0

I wrote this interface:

//The idea is to use EHPrint to construct the error msg and then raise an error or
//a warning, etc. This removes the need to implement all 3 'Raise' functions
//as taking variable param list reducing code.                                                   
class ErrorHandler                                                            
{   
    public:
        virtual void RaiseError(bool, int) = 0;                     
        virtual void RaiseWarning(int) = 0;                                   
        virtual void RaiseMsg() = 0;                                          

        __attribute__((format(printf, 1, 2)))
        virtual const char* EHPrint(const char*, ...) = 0;                    

        virtual ~ErrorHandler(){}                                             
};

Forget multi-threading issues because one object will only be used in one thread. Implementation classes can log, raise errors to user or terminate as needed. The drawback is that you have to call EHPrint before you want to raise an error, etc. Any way I can make this more beautiful?

EDIT:
I’d really like to just call one function when I want to RaiseError. As of now, I have to call EHPrintf and then call RaiseError.

EDIT2:
I think it is my mistake that I coupled error handling and error logging together. Will try and separate them and see.

EDIT3:
I thought I should post the logger now:

class Logger                                                        
{   
    public:
        enum LogType                                                
        {   
            LT_DEBUG = 0,                                           
            LT_WARNING,                                             
            LT_ERROR,                                               
            LT_STAT,                                                
            LT_TEXT                                                 
        };                                                          

        __attribute__((format(printf, 5, 6)))                       
        virtual const char* EHLog(LogType,                          
                int,
                const char*,                                        
                int,
                const char*,                                        
                ...) = 0;                                           

        virtual ~Logger(){}                                         
};

Which clears up the code because logging is separate now.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T17:38:08+00:00Added an answer on May 17, 2026 at 5:38 pm

    Most logging libraries that support multiple levels of logmessages use only one function for generating the messages and this function takes an additional parameter indicating the level of the log message.

    In your structure, that could look like this:

    class ErrorHandler                                                            
    {   
        private:
            virtual void RaiseError(bool, int) = 0;                     
            virtual void RaiseWarning(int) = 0;                                   
            virtual void RaiseMsg() = 0;                                          
        public:
            enum LogLevel {
                ERROR,
                WARNING,
                MSG
            };
    
            __attribute__((format(printf, 2, 3)))
            virtual const char* EHPrint(enum LogLevel, const char*, ...) = 0;                    
    
            virtual ~ErrorHandler(){}                                             
    };
    

    Some additional points you have to consider:

    1. Variadic functions are not safe to use with non-POD types. If you use printf-style functions for logging, your users are restricted to logging only primitive types. A class like std::string can not be used.
    2. With the two-call setup for preparing the message and sending it, you must be prepared that users call EHPrint multiple times before calling one of the RaiseXXX functions.

    Furthermore, I second the comment from DumbCoder to take a look at existing logging libraries, if only to see what they have in common in their design and/or API.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a custom database class that I wrote myself, and I also have
So, maybe this is a bad design; I don't know. But say I have
I have this small PHP script: <?php session_start(); $var = array(); $var['key'] = 'Var
I'm looking to write a tool that aims to convert debug symbols of one
I work at a small computer shop, and we have to analyze windows minidumps
I've got a class with some functions which realistically are just 'helper' methods that
I know the title is really unclear, so give me a moment :) I'm
I am afraid that several terminologies in my question are wrong. Please bear with
It's been a while since I've done Java I/O, and I'm not aware of
Is it possible to get WSDL.exe to generate interfaces as well as, or instead

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.