Aleph-w 7.10.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
aleph-exceptions.H File Reference

Custom exception classes with source location tracking. More...

#include <exception>
#include <sstream>
#include <ahUtils.H>
Include dependency graph for aleph-exceptions.H:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  AlephException
 Aleph exception class. More...
 
struct  MinMaxReversed
 
struct  InvalidCsvHeader
 
struct  InvalidCsvRow
 
struct  InvalidValue
 
struct  OutOfMemory
 
struct  OutOfRange
 
struct  ValueNotFound
 
struct  CommandLineError
 
struct  InvariantError
 
struct  SizeMismatch
 
struct  InvalidConversion
 
struct  NameNotFound
 
struct  InvalidSize
 
struct  InvalidRange
 
struct  InvalidUnit
 
struct  DuplicatedOperation
 
struct  DuplicatedName
 
struct  InvalidRead
 
struct  FileNotFound
 

Macros

#define ALEPH_EXCEPTIONS_DEPRECATED    [[deprecated("aleph-exceptions.H goes in 8.0.0; use the macros of ah-errors.H instead")]]
 
#define DEFINE_ALEPH_EXCEPTION(name, category_msg)
 Define a new exception.
 
#define ALEPHTHROW(type, msg)   throw type(__LINE__, __FILE__, #type, msg)
 Macro for throwing an aleph exception.
 
#define ALEPH_DEFINE_DEPRECATED_EXCEPTION(name, category_msg)
 

Detailed Description

Custom exception classes with source location tracking.

This file provides AlephException, a custom exception class that captures file name, line number, and function name where the exception was thrown.

Key Features

  • Inherits from std::runtime_error
  • Captures source location (file, line, function)
  • Human-readable error messages
  • Macro for defining new exception types

AlephException Members

  • line_number: Line where exception was thrown
  • file_name: Source file name
  • function_name: Function where thrown

Defining Custom Exceptions

Use the DEFINE_ALEPH_EXCEPTION macro:

// Usage:
throw MyError(__FILE__, __LINE__, "my_function", "Something failed");
#define DEFINE_ALEPH_EXCEPTION(name, category_msg)
Define a new exception.

Recommended Alternative

For new code, prefer using ah-errors.H macros which provide automatic source location capture:

ah_domain_error_if(x < 0, "x must be positive");
#define ah_domain_error_if(C)
Throws std::domain_error if condition holds.
Definition ah-errors.H:670
Deprecated:
Nothing of Aleph but LFit uses it, which throws SizeMismatch until 8.0.0: aleph-exceptions.H goes in 8.0.0, and LFit throws then std::invalid_argument, as the macros of ah-errors.H do. Its classes are [[deprecated]], and DEFINE_ALEPH_EXCEPTION, which derives from AlephException, warns where it is used. To catch the errors of LFit both before and after 8.0.0, catch std::exception.
See also
ah-errors.H Modern error handling macros
ahUtils.H Utility functions used by exceptions
Author
Leandro Rabindranath León

Definition in file aleph-exceptions.H.

Macro Definition Documentation

◆ ALEPH_DEFINE_DEPRECATED_EXCEPTION

#define ALEPH_DEFINE_DEPRECATED_EXCEPTION (   name,
  category_msg 
)
Value:
{ \
name(const size_t line_number, \
const std::string & file_name, \
const std::string & type, \
const std::string & msg) \
: AlephException(#category_msg, line_number, file_name, type, msg) {} \
};
#define ALEPH_EXCEPTIONS_DEPRECATED
Aleph exception class.

Definition at line 212 of file aleph-exceptions.H.

◆ ALEPH_EXCEPTIONS_DEPRECATED

#define ALEPH_EXCEPTIONS_DEPRECATED    [[deprecated("aleph-exceptions.H goes in 8.0.0; use the macros of ah-errors.H instead")]]

Definition at line 107 of file aleph-exceptions.H.

◆ ALEPHTHROW

#define ALEPHTHROW (   type,
  msg 
)    throw type(__LINE__, __FILE__, #type, msg)

Macro for throwing an aleph exception.

Parameters
[in]typealeph exception class name
[in]msgmessage describing the error
Author
Leandro Rabindranath León
Deprecated:
aleph-exceptions.H goes in 8.0.0: use the macros of ah-errors.H. The classes that it throws are deprecated.

Definition at line 201 of file aleph-exceptions.H.

◆ DEFINE_ALEPH_EXCEPTION

#define DEFINE_ALEPH_EXCEPTION (   name,
  category_msg 
)
Value:
struct name : public AlephException \
{ \
name(const size_t line_number, \
const std::string & file_name, \
const std::string & type, \
const std::string & msg) \
: AlephException(#category_msg, line_number, file_name, type, msg) {} \
\
private: \
/* GCC does not warn of a deprecated base class: of this, it does */ \
using aleph_deprecated_base_ = AlephException; \
};

Define a new exception.

Parameters
[in]nameof the exception
[in]category_msg
Author
Leandro Rabindranath Leon
Deprecated:
aleph-exceptions.H goes in 8.0.0: the class that it defines derives from the deprecated AlephException, and the macro warns where it is used.

Definition at line 178 of file aleph-exceptions.H.