From 0d7a8cca790e8fa71a83e4dce09fbe5a0af38cbc Mon Sep 17 00:00:00 2001 From: vaxerski <43317083+vaxerski@users.noreply.github.com> Date: Wed, 6 Jul 2022 16:17:58 +0200 Subject: [PATCH] use C++ throw methods instead of printf and exit --- src/Compositor.cpp | 19 +++++++------------ src/defines.hpp | 2 -- src/main.cpp | 2 +- 3 files changed, 8 insertions(+), 15 deletions(-) diff --git a/src/Compositor.cpp b/src/Compositor.cpp index e6de59d5..a8a3116a 100644 --- a/src/Compositor.cpp +++ b/src/Compositor.cpp @@ -28,23 +28,20 @@ CCompositor::CCompositor() { if (!m_sWLRBackend) { Debug::log(CRIT, "m_sWLRBackend was NULL!"); - RIP("m_sWLRBackend NULL!"); - return; + throw std::runtime_error("wlr_backend_autocreate() failed!"); } m_iDRMFD = wlr_backend_get_drm_fd(m_sWLRBackend); if (m_iDRMFD < 0) { Debug::log(CRIT, "Couldn't query the DRM FD!"); - RIP("DRMFD NULL!"); - return; + throw std::runtime_error("wlr_backend_get_drm_fd() failed!"); } m_sWLRRenderer = wlr_gles2_renderer_create_with_drm_fd(m_iDRMFD); if (!m_sWLRRenderer) { Debug::log(CRIT, "m_sWLRRenderer was NULL!"); - RIP("m_sWLRRenderer NULL!"); - return; + throw std::runtime_error("wlr_gles2_renderer_create_with_drm_fd() failed!"); } wlr_renderer_init_wl_display(m_sWLRRenderer, m_sWLDisplay); @@ -53,16 +50,14 @@ CCompositor::CCompositor() { if (!m_sWLRAllocator) { Debug::log(CRIT, "m_sWLRAllocator was NULL!"); - RIP("m_sWLRAllocator NULL!"); - return; + throw std::runtime_error("wlr_allocator_autocreate() failed!"); } m_sWLREGL = wlr_gles2_renderer_get_egl(m_sWLRRenderer); if (!m_sWLREGL) { Debug::log(CRIT, "m_sWLREGL was NULL!"); - RIP("m_sWLREGL NULL!"); - return; + throw std::runtime_error("wlr_gles2_renderer_get_egl() failed!"); } m_sWLRCompositor = wlr_compositor_create(m_sWLDisplay, m_sWLRRenderer); @@ -248,7 +243,7 @@ void CCompositor::startCompositor() { if (!m_szWLDisplaySocket) { Debug::log(CRIT, "m_szWLDisplaySocket NULL!"); wlr_backend_destroy(m_sWLRBackend); - RIP("m_szWLDisplaySocket NULL!"); + throw std::runtime_error("m_szWLDisplaySocket was null! (wl_display_add_socket_auto failed)"); } setenv("WAYLAND_DISPLAY", m_szWLDisplaySocket, 1); @@ -261,7 +256,7 @@ void CCompositor::startCompositor() { Debug::log(CRIT, "Backend did not start!"); wlr_backend_destroy(m_sWLRBackend); wl_display_destroy(m_sWLDisplay); - RIP("Backend did not start!"); + throw std::runtime_error("The backend could not start!"); } wlr_xcursor_manager_set_cursor_image(m_sWLRXCursorMgr, "left_ptr", m_sWLRCursor); diff --git a/src/defines.hpp b/src/defines.hpp index 80750c23..375f0119 100644 --- a/src/defines.hpp +++ b/src/defines.hpp @@ -16,8 +16,6 @@ #define ISDEBUG false #endif -#define RIP(format, ... ) { fprintf(stderr, format "\n", ##__VA_ARGS__); exit(EXIT_FAILURE); } - #define LISTENER(name) void listener_##name(wl_listener*, void*); inline wl_listener listen_##name = { .notify = listener_##name }; #define DYNLISTENFUNC(name) void listener_##name(void*, void*); #define DYNLISTENER(name) CHyprWLListener hyprListener_##name; diff --git a/src/main.cpp b/src/main.cpp index a437430f..0947f375 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -12,7 +12,7 @@ bool ignoreSudo = false; int main(int argc, char** argv) { if (!getenv("XDG_RUNTIME_DIR")) - RIP("XDG_RUNTIME_DIR not set!"); + throw std::runtime_error("XDG_RUNTIME_DIR is not set!"); // parse some args for (int i = 1; i < argc; ++i) {