Skip to content

Change const char * to std::string in BaseException #101

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

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions modules/ugdk-core/include/ugdk/system/exceptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ namespace system {

class BaseException {
public:
BaseException(const char * fmt, ...);
template <typename... Args>
BaseException(const std::string& fmt, Args... args) {
set_reason(fmt.c_str(), args...);
}
virtual ~BaseException() throw() {}

inline virtual const char * what() const throw() {
Expand All @@ -17,6 +20,7 @@ class BaseException {

private:
std::string reason_;
void set_reason(const char* fmt, ...);
};

class InvalidOperation : public BaseException {
Expand All @@ -34,4 +38,4 @@ void AssertCondition(bool condition, Args... args) {
} // namespace system
} // namespace ugdk

#endif // UGDK_SYSTEM_EXCEPTIONS_H_
#endif // UGDK_SYSTEM_EXCEPTIONS_H_
3 changes: 1 addition & 2 deletions modules/ugdk-core/src/system/exceptions.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@
namespace ugdk {
namespace system {

BaseException::BaseException(const char * fmt, ...)
{
void BaseException::set_reason(const char* fmt, ...) {
va_list args;
int size_buffer = 256, size_out;
char * buffer;
Expand Down