Adds exception support
This commit is contained in:
1 parent
2fedb29014
commit
34e1dd0c33
9 files changed
+55
-19
No files matched your search
@@ -1,5 +1,5 @@
|
||||
|
||||
add_library(Core OBJECT EventBus.cpp ConfigManager.cpp Logger.cpp)
|
||||
add_library(Core OBJECT EventBus.cpp ConfigManager.cpp Logger.cpp Exception.cpp)
|
||||
|
||||
target_include_directories(Core PUBLIC include)
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ Event& EventBus::registerEvent(const string& eventID) {
|
||||
}
|
||||
|
||||
void EventBus::run() {
|
||||
//_logger.debug.ln("Hi from EventBus run method! From within Event Thread!");
|
||||
_logger.warn.ln("Hi from EventBus run method! From within Event Thread! Dont forget to make Logger class thread-safe!");
|
||||
}
|
||||
|
||||
// =============================== Event Class ================================
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
#include "Exception.hpp"
|
||||
|
||||
namespace Plains {
|
||||
namespace Core {
|
||||
|
||||
using std::string;
|
||||
|
||||
Exception::Exception(const char* msg) : _msg(msg) {}
|
||||
|
||||
const char* Exception::what() const noexcept { return _msg; }
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}}
|
||||
@@ -3,5 +3,6 @@
|
||||
#include "EventBus.hpp"
|
||||
#include "Logger.hpp"
|
||||
#include "ConfigManager.hpp"
|
||||
#include "Exception.hpp"
|
||||
//Include further classes here
|
||||
#endif
|
||||
@@ -0,0 +1,24 @@
|
||||
#ifndef EXCEPTION_HPP
|
||||
#define EXCEPTION_HPP
|
||||
#include <exception>
|
||||
#include <string>
|
||||
|
||||
namespace Plains {
|
||||
namespace Core {
|
||||
|
||||
using std::exception;
|
||||
using std::string;
|
||||
|
||||
class Exception: public exception
|
||||
{
|
||||
public:
|
||||
Exception(const char* msg);
|
||||
const char* what() const noexcept;
|
||||
|
||||
private:
|
||||
const char* _msg;
|
||||
};
|
||||
|
||||
}}
|
||||
|
||||
#endif
|
||||
@@ -38,7 +38,6 @@ class Logger {
|
||||
bool _lineIsPrefixed;
|
||||
Logger& _parent;
|
||||
const Logger::Level _level;
|
||||
const char* _colorCode;
|
||||
void prefixLine(bool resetToFalse = false);
|
||||
public:
|
||||
Sink(const Level level, Logger& parent);
|
||||
|
||||
+10
-11
@@ -13,11 +13,6 @@ using std::string;
|
||||
int main(int args, char **argv) {
|
||||
Logger logger(Logger::DEBUG);
|
||||
|
||||
//logger.debug.ln ("Debug message");
|
||||
//logger.info.ln ("Info message");
|
||||
//logger.warn.ln ("Warning message");
|
||||
//logger.fatal.ln ("Fatal message");
|
||||
|
||||
logger.info.ln ("Starting PlaiNS...");
|
||||
|
||||
try
|
||||
@@ -31,7 +26,7 @@ int main(int args, char **argv) {
|
||||
EventBus eventBus(logger);
|
||||
Resolver::Server resolver(logger, eventBus);
|
||||
|
||||
|
||||
/*
|
||||
// Some test code below:
|
||||
class Testi : public EventSubscriber {
|
||||
public:
|
||||
@@ -51,11 +46,9 @@ int main(int args, char **argv) {
|
||||
e2.subscribe(&testi2);
|
||||
|
||||
e1.fire();
|
||||
|
||||
*/
|
||||
|
||||
//Record testrec = ARecord();
|
||||
//logger.debug.ln ("Running DNS resolver...");
|
||||
|
||||
// End of Testcode
|
||||
|
||||
//resolver.run();
|
||||
@@ -63,9 +56,15 @@ int main(int args, char **argv) {
|
||||
// Run something on main thread...
|
||||
logger.info.ln ("Shutting down PlaiNS. Good Bye!");
|
||||
}
|
||||
catch (std::exception& e)
|
||||
catch (Exception& e)
|
||||
{
|
||||
logger.debug << "Exception: " << e.what() << Logger::commit;
|
||||
logger.fatal << "Uncaught Exception: " << e.what() << Logger::commit;
|
||||
return 1;
|
||||
}
|
||||
catch (int e)
|
||||
{
|
||||
logger.fatal << "Uncaught Exception with error code " << e << Logger::commit;
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
#include "Message.hpp"
|
||||
#include <fstream>
|
||||
|
||||
#include <iostream>
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
@@ -54,6 +53,7 @@ Server::Server(Logger& logger, EventBus& eventBus)
|
||||
_eventBus(eventBus)
|
||||
{
|
||||
_logger.debug.ln ("Starting Resolver...");
|
||||
//throw Exception("Testi");
|
||||
/*
|
||||
_logger.debug << "Testing some stuff..." << Logger::commit;
|
||||
_logger.debug << "Message header overall size: " << sizeof(Message::Header) << Logger::commit;
|
||||
|
||||
@@ -10,6 +10,7 @@ namespace Resolver {
|
||||
|
||||
using Core::EventBus;
|
||||
using Core::Logger;
|
||||
using Core::Exception;
|
||||
|
||||
|
||||
class Server
|
||||
@@ -35,10 +36,6 @@ class Server
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}}
|
||||
|
||||
#endif
|
||||
Reference in new issue
Block a user