-
Notifications
You must be signed in to change notification settings - Fork 4.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow exception handling to be disabled. #136
Comments
cppformat uses the following method to make exceptions optional: #if FMT_EXCEPTIONS
# define FMT_TRY try
# define FMT_CATCH(x) catch (x)
#else
# define FMT_TRY if (true)
# define FMT_CATCH(x) if (false)
#endif
#ifndef FMT_THROW
# if FMT_EXCEPTIONS
# define FMT_THROW(x) throw x
# else
# define FMT_THROW(x) assert(false)
# endif
#endif |
which means log errors would be just ignored if exceptions are disabled? |
If you follow the cppformat style, then yes. Either way this is just giving the choice to the user of your library to disable exceptions. It's up to them deal with the consiquences of doing so. The default would to have exceptions enabled. |
Sorry, would cause too much code diversion. |
This would be nice to have. A lot of embedded systems that use C++ can't use exceptions for performance reasons. |
I am in the exact same boat ... just dumped easyloggingpp because of the exceptions. Disabling exceptions is a key requirement for our particular system and IoT-based systems in general. I won't be able to use this logger because of that. I do like the speed performance spdlog offers. |
reopened due to popular request |
I have something similar but different: my program has exceptions enabled but I do not want a |
A fairly common use case for logging is to keep track of errors in situations where you cannot throw an exception. Therefore it makes sense for a logging library to never throw exceptions, or at least make it optional. Moreover projects such as games are developed with -fno-exceptions and -fno-rtti, and they can't enable exceptions because of one library. Theoretically if all |
Should be easy, yes. I was thinking to add to the API some kind of |
@gabime I'm happy to work on a PR for this as it's functionality I'd like as well. Where would be a good place to store a function pointer to a user-supplied error handler? |
Implemented in 39cdd08. Exceptions will be thrown only if the ctor failed. If an error happens during logging, the library will print an error message to stderr (max rate of 1 message per minute). This behaviour can be changed using spdlog::set_error_handler(new_handler_fun) or (for specific logger) logger->set_error_handler(new_handler_fun): |
There's a copy of fmt inside spdlog. Are the exceptions inside that disabled by default as well? So can I just mark any wrappers with |
I build my code without exception handling, and spdlog cannot build as it uses exceptions.
Would you be able to make exception support optional for spdlog?
The text was updated successfully, but these errors were encountered: