Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Marked old exception types obsolete #904

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 3 additions & 33 deletions docs/sphinx_rsts/intro/exceptions_in_openfhe.rst
Original file line number Diff line number Diff line change
@@ -1,45 +1,15 @@
Throwing Exceptions in OpenFHE
===============================

The OpenFHE library will throw a openfhe_error exception in the event of certain unrecoverable errors. A openfhe_error is a subclass of ``std::exception``. The library *actually* throws an exception which is a subclass of openfhe_error.
The OpenFHE library will throw an OpenFHEException exception in the event of an unrecoverable error. A openfhe_error is a subclass of ``std::exception``.


Programmers use the OPENFHE_THROW macro in exception.h to generate an exception. Each exception includes the filename and line number at which the exception was thrown as well as a programmer-defined message.
Programmers use the OPENFHE_THROW macro in exception.h to generate an exception. Each exception includes the filename, the function name and line number at which the exception was thrown as well as a programmer-defined message.


Exceptions and the methods associated with them are defined in ``src/core/include/utils/exception.h``.
OpenFHEException is defined in ``src/core/include/utils/exception.h``.


Available Exceptions
-----------------------

The available exceptions are as follows

config_error
^^^^^^^^^^^^^^^^

This exception is thrown whenever the user of the library supplies configuration parameters that cannot be used to configure OpenFHE. An example of this would be providing a ciphertext modulus that is not a prime number, or providing a plaintext modulus that cannot be used with a particular encoding type.

math_error
^^^^^^^^^^^^^^^^

This exception is thrown whenever a math error occurs during the operation of the library. An example of this would be an overflow.

serialization_error
^^^^^^^^^^^^^^^^^^^^

This exception is thrown whenever a fatal serialization error occurs. For example, if a required field is missing, this exception is thrown.

not_implemented_error
^^^^^^^^^^^^^^^^^^^^^

This exception is thrown if a method is unimplemented. An example of this is a circumstance where a default implementation is provided in a base class, but an overridden exception is not provided in the derived class.

not_available_error
^^^^^^^^^^^^^^^^^^^

This exception is thrown if a method is not available for a given configuration. For example, an arbitrary cyclotomics method is not available for a power-of-2 configuration.

Exceptions in critical regions and OMP threads
-----------------------------------------------

Expand Down
25 changes: 17 additions & 8 deletions src/core/include/utils/exception.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,9 @@ class ThreadException {
// });
// }
// e.Rethrow();
class openfhe_error : public std::runtime_error {

class __attribute__((deprecated("OpenFHEException is the only exception class to be used in OpenFHE now.")))
openfhe_error : public std::runtime_error {
std::string filename;
int linenum;
std::string message;
Expand All @@ -123,40 +125,47 @@ class openfhe_error : public std::runtime_error {
}
};

class config_error : public openfhe_error {
class __attribute__((deprecated("OpenFHEException is the only exception class to be used in OpenFHE now.")))
config_error : public openfhe_error {
public:
config_error(const std::string& file, int line, const std::string& what) : openfhe_error(file, line, what) {}
};

class math_error : public openfhe_error {
class __attribute__((deprecated("OpenFHEException is the only exception class to be used in OpenFHE now."))) math_error
: public openfhe_error {
public:
math_error(const std::string& file, int line, const std::string& what) : openfhe_error(file, line, what) {}
};

class not_implemented_error : public openfhe_error {
class __attribute__((deprecated("OpenFHEException is the only exception class to be used in OpenFHE now.")))
not_implemented_error : public openfhe_error {
public:
not_implemented_error(const std::string& file, int line, const std::string& what)
: openfhe_error(file, line, what) {}
};

class not_available_error : public openfhe_error {
class __attribute__((deprecated("OpenFHEException is the only exception class to be used in OpenFHE now.")))
not_available_error : public openfhe_error {
public:
not_available_error(const std::string& file, int line, const std::string& what) : openfhe_error(file, line, what) {}
};

class type_error : public openfhe_error {
class __attribute__((deprecated("OpenFHEException is the only exception class to be used in OpenFHE now."))) type_error
: public openfhe_error {
public:
type_error(const std::string& file, int line, const std::string& what) : openfhe_error(file, line, what) {}
};

// use this error when serializing openfhe objects
class serialize_error : public openfhe_error {
class __attribute__((deprecated("OpenFHEException is the only exception class to be used in OpenFHE now.")))
serialize_error : public openfhe_error {
public:
serialize_error(const std::string& file, int line, const std::string& what) : openfhe_error(file, line, what) {}
};

// use this error when deserializing openfhe objects
class deserialize_error : public openfhe_error {
class __attribute__((deprecated("OpenFHEException is the only exception class to be used in OpenFHE now.")))
deserialize_error : public openfhe_error {
public:
deserialize_error(const std::string& file, int line, const std::string& what) : openfhe_error(file, line, what) {}
};
Expand Down
2 changes: 1 addition & 1 deletion src/pke/include/schemebase/base-fhe.h
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ class FHEBase {
*/
virtual void EvalCompareSwitchPrecompute(const CryptoContextImpl<Element>& ccCKKS, uint32_t pLWE, double scaleSign,
bool unit) {
OPENFHE_THROW(not_implemented_error, "EvalCompareSwitchPrecompute is not supported for this scheme");
OPENFHE_THROW("EvalCompareSwitchPrecompute is not supported for this scheme");
}

/**
Expand Down