use C++ throw methods instead of printf and exit

This commit is contained in:
vaxerski 2022-07-06 16:17:58 +02:00
parent 9655d0c138
commit 0d7a8cca79
3 changed files with 8 additions and 15 deletions

View file

@ -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);

View file

@ -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;

View file

@ -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) {