Skip to content

Commit

Permalink
Print error message when the class constructor fails
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolarevelant committed Oct 21, 2023
1 parent 51b4de5 commit 3a2047c
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 4 deletions.
6 changes: 5 additions & 1 deletion src/ChessboardGrid/ChessboardGrid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,12 @@ ChessboardGrid::~ChessboardGrid() = default;

ChessboardGrid::ChessboardGrid(const ImageProviderCB &images, const ColorProviderCB &colors,
wxWindow *parent, wxWindowID winId, const wxPoint &pos) : ChessboardGrid() {
if (!Create(images, colors, parent, winId, pos))
if (!Create(images, colors, parent, winId, pos)) {
#ifdef DEBUG
std::cerr << "Cannot create ChessboardGrid" << std::endl;
#endif
throw std::exception();
}
}

bool ChessboardGrid::Create(const ImageProviderCB &images, const ColorProviderCB &colors,
Expand Down
6 changes: 5 additions & 1 deletion src/ChessboardSquare/ChessboardSquare.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,12 @@ ChessboardSquare::ChessboardSquare() {
}

ChessboardSquare::ChessboardSquare(int size, wxWindow *parent, wxWindowID windowId) : ChessboardSquare() {
if (!Create(size, parent, windowId))
if (!Create(size, parent, windowId)) {
#ifdef DEBUG
std::cerr << "Cannot create ChessboardSquare" << std::endl;
#endif
throw std::exception();
}
}

bool ChessboardSquare::Create(int size, wxWindow *parent, wxWindowID windowId) {
Expand Down
6 changes: 5 additions & 1 deletion src/Frame/Frame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,12 @@
Frame::Frame() = default;

Frame::Frame(wxWindow *parent, const std::string &theme) : Frame() {
if (!Create(parent, theme))
if (!Create(parent, theme)) {
#ifdef DEBUG
std::cerr << "Cannot create Frame" << std::endl;
#endif
throw std::exception();
}
}

bool Frame::Create(wxWindow *parent, const std::string &theme) {
Expand Down
9 changes: 8 additions & 1 deletion src/MatchManager/MatchManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@
#include "MatchManager.h"

MatchManager::MatchManager(ChessboardGrid *chessboard) {
if (chessboard == nullptr)
if (chessboard == nullptr) {
#ifdef DEBUG
std::cerr << "Cannot create MatchManager: chessboard == nullptr" << std::endl;
#endif
throw std::exception();
}

chessboard->Bind(wxEVT_LEFT_UP, &MatchManager::onChessboardSquareClick, this);
chessboard->Bind(wxEVT_MENU, &MatchManager::onThreadFinish, this, THREAD_ID);
Expand Down Expand Up @@ -150,8 +154,11 @@ void MatchManager::makePCMove() {

void MatchManager::onThreadFinish(wxCommandEvent &evt) {
if (!algorithmThread) {
#ifdef DEBUG
std::cerr << "Unwanted thread finished" << std::endl;
#endif
delete static_cast<GameUtils::Move *>(evt.GetClientData());
exit(1);
}
algorithmThread = nullptr;

Expand Down

0 comments on commit 3a2047c

Please sign in to comment.