Skip to content

Commit

Permalink
Create workflows,
Browse files Browse the repository at this point in the history
  • Loading branch information
JMARRUJO91 committed May 27, 2024
1 parent 5c25cd7 commit 0de260c
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions .github/workflows,
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#ifndef __CDMATHEXCEPTION_HXX__
#define __CDMATHEXCEPTION_HXX__

#include <string>
#include <exception>
#include <sstream> // For building formatted error messages

class CdmathException : public std::exception
{
public:
CdmathException(const std::string& reason) : _reason(reason) {}
CdmathException(const std::string& reason, const std::string& file, int line)
: _reason(BuildMessage(reason, file, line)) {}

~CdmathException() throw () {} // Virtual destructor

const char* what() const throw() override {
return _reason.c_str();
}

private:
std::string _reason;

// Helper function to format the error message
static std::string BuildMessage(const std::string& reason, const std::string& file, int line) {
std::ostringstream oss;
oss << reason << " (File: " << file << ", Line: " << line << ")";
return oss.str();
}
};

#endif
#include "CdmathException.hxx"

double divide(double a, double b) {
if (b == 0.0) {
throw CdmathException("Division by zero", __FILE__, __LINE__);
}
return a / b;
}

0 comments on commit 0de260c

Please sign in to comment.