forked from Alepha/Alepha
Require exceptions to be one of specific defined grades.
Merge branch 'exception-improvements'
This commit is contained in:
64
Exception.h
64
Exception.h
@ -12,6 +12,8 @@ static_assert( __cplusplus > 2020'99 );
|
|||||||
#include <string_view>
|
#include <string_view>
|
||||||
#include <typeindex>
|
#include <typeindex>
|
||||||
|
|
||||||
|
#include "Concepts.h"
|
||||||
|
|
||||||
namespace Alepha::Hydrogen ::detail:: Exception_m
|
namespace Alepha::Hydrogen ::detail:: Exception_m
|
||||||
{
|
{
|
||||||
inline namespace exports
|
inline namespace exports
|
||||||
@ -100,7 +102,27 @@ namespace Alepha::Hydrogen ::detail:: Exception_m
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
template< typename unique_handle, typename GradeType, typename ... Bases >
|
class Exception;
|
||||||
|
class Condition;
|
||||||
|
class Notification;
|
||||||
|
class Error;
|
||||||
|
class CriticalError;
|
||||||
|
class Violation;
|
||||||
|
|
||||||
|
using Grades= TypeList
|
||||||
|
<
|
||||||
|
Exception,
|
||||||
|
Condition,
|
||||||
|
Notification,
|
||||||
|
Error,
|
||||||
|
CriticalError,
|
||||||
|
Violation
|
||||||
|
>;
|
||||||
|
|
||||||
|
template< typename T >
|
||||||
|
concept ExceptionGrade= list_contains_v< Grades, T >;
|
||||||
|
|
||||||
|
template< typename unique_handle, ExceptionGrade GradeType, typename ... Bases >
|
||||||
using create_exception= synthetic_exception< unique_handle, GradeType, Bases ... >;
|
using create_exception= synthetic_exception< unique_handle, GradeType, Bases ... >;
|
||||||
|
|
||||||
template< typename Exc >
|
template< typename Exc >
|
||||||
@ -124,7 +146,7 @@ namespace Alepha::Hydrogen ::detail:: Exception_m
|
|||||||
const Target &
|
const Target &
|
||||||
as() const
|
as() const
|
||||||
{
|
{
|
||||||
if( not is_a< const Target * >() )
|
if( not is_a< Target >() )
|
||||||
{
|
{
|
||||||
// TODO: Structured exception recovery here...
|
// TODO: Structured exception recovery here...
|
||||||
}
|
}
|
||||||
@ -310,48 +332,48 @@ namespace Alepha::Hydrogen ::detail:: Exception_m
|
|||||||
public:
|
public:
|
||||||
std::string_view resourceName() const noexcept final { return storage; }
|
std::string_view resourceName() const noexcept final { return storage; }
|
||||||
};
|
};
|
||||||
class NamedResourceException : public virtual synthetic_exception< struct named_resource_throwable, Exception >, virtual public NamedResourceInterface {};
|
class NamedResourceException : public virtual create_exception< struct named_resource_throwable, Exception >, virtual public NamedResourceInterface {};
|
||||||
using AnyTaggedNamedResourceException= NamedResourceException::any_tagged_type;
|
using AnyTaggedNamedResourceException= NamedResourceException::any_tagged_type;
|
||||||
template< typename tag >
|
template< typename tag >
|
||||||
using TaggedNamedResourceException= NamedResourceException::tagged_type< tag >;
|
using TaggedNamedResourceException= NamedResourceException::tagged_type< tag >;
|
||||||
|
|
||||||
using NamedResourceNotification= synthetic_exception< struct named_resource_notification, Notification, NamedResourceException >;
|
using NamedResourceNotification= create_exception< struct named_resource_notification, Notification, NamedResourceException >;
|
||||||
using AnyTaggedNamedResourceNotification= NamedResourceNotification::any_tagged_type;
|
using AnyTaggedNamedResourceNotification= NamedResourceNotification::any_tagged_type;
|
||||||
template< typename tag >
|
template< typename tag >
|
||||||
using TaggedNamedResourceNotification= NamedResourceNotification::tagged_type< tag >;
|
using TaggedNamedResourceNotification= NamedResourceNotification::tagged_type< tag >;
|
||||||
|
|
||||||
using NamedResourceError= synthetic_exception< struct named_resource_exception, Error, NamedResourceException >;
|
using NamedResourceError= create_exception< struct named_resource_exception, Error, NamedResourceException >;
|
||||||
using AnyTaggedNamedResourceError= NamedResourceError::any_tagged_type;
|
using AnyTaggedNamedResourceError= NamedResourceError::any_tagged_type;
|
||||||
template< typename tag >
|
template< typename tag >
|
||||||
using TaggedNamedResourceError= NamedResourceError::tagged_type< tag >;
|
using TaggedNamedResourceError= NamedResourceError::tagged_type< tag >;
|
||||||
|
|
||||||
using NamedResourceCriticalError= synthetic_exception< struct named_resource_error, CriticalError, NamedResourceException >;
|
using NamedResourceCriticalError= create_exception< struct named_resource_error, CriticalError, NamedResourceException >;
|
||||||
using AnyTaggedNamedResourceCriticalError= NamedResourceCriticalError::any_tagged_type;
|
using AnyTaggedNamedResourceCriticalError= NamedResourceCriticalError::any_tagged_type;
|
||||||
template< typename tag >
|
template< typename tag >
|
||||||
using TaggedNamedResourceCriticalError= NamedResourceCriticalError::tagged_type< tag >;
|
using TaggedNamedResourceCriticalError= NamedResourceCriticalError::tagged_type< tag >;
|
||||||
|
|
||||||
using NamedResourceViolation= synthetic_exception< struct named_resource_violation, Violation, NamedResourceException >;
|
using NamedResourceViolation= create_exception< struct named_resource_violation, Violation, NamedResourceException >;
|
||||||
using AnyTaggedNamedResourceViolation= NamedResourceViolation::any_tagged_type;
|
using AnyTaggedNamedResourceViolation= NamedResourceViolation::any_tagged_type;
|
||||||
template< typename tag >
|
template< typename tag >
|
||||||
using TaggedNamedResourceViolation= NamedResourceViolation::tagged_type< tag >;
|
using TaggedNamedResourceViolation= NamedResourceViolation::tagged_type< tag >;
|
||||||
|
|
||||||
class OutOfRangeException
|
class OutOfRangeException
|
||||||
: virtual public synthetic_exception< struct out_of_range_throwable, Exception > {};
|
: virtual public create_exception< struct out_of_range_throwable, Exception > {};
|
||||||
using AnyTaggedOutOfRangeException= OutOfRangeException::any_tagged_type;
|
using AnyTaggedOutOfRangeException= OutOfRangeException::any_tagged_type;
|
||||||
template< typename tag >
|
template< typename tag >
|
||||||
using TaggedOutOfRangeException= OutOfRangeException::tagged_type< tag >;
|
using TaggedOutOfRangeException= OutOfRangeException::tagged_type< tag >;
|
||||||
|
|
||||||
using OutOfRangeError= synthetic_exception< struct out_of_range_throwable, Error, OutOfRangeException >;
|
using OutOfRangeError= create_exception< struct out_of_range_throwable, Error, OutOfRangeException >;
|
||||||
using AnyTaggedOutOfRangeError= OutOfRangeError::any_tagged_type;
|
using AnyTaggedOutOfRangeError= OutOfRangeError::any_tagged_type;
|
||||||
template< typename tag >
|
template< typename tag >
|
||||||
using TaggedOutOfRangeError= OutOfRangeError::tagged_type< tag >;
|
using TaggedOutOfRangeError= OutOfRangeError::tagged_type< tag >;
|
||||||
|
|
||||||
using OutOfRangeCriticalError= synthetic_exception< struct out_of_range_throwable, CriticalError, OutOfRangeException >;
|
using OutOfRangeCriticalError= create_exception< struct out_of_range_throwable, CriticalError, OutOfRangeException >;
|
||||||
using AnyTaggedOutOfRangeCriticalError= OutOfRangeCriticalError::any_tagged_type;
|
using AnyTaggedOutOfRangeCriticalError= OutOfRangeCriticalError::any_tagged_type;
|
||||||
template< typename tag >
|
template< typename tag >
|
||||||
using TaggedOutOfRangeCriticalError= OutOfRangeCriticalError::tagged_type< tag >;
|
using TaggedOutOfRangeCriticalError= OutOfRangeCriticalError::tagged_type< tag >;
|
||||||
|
|
||||||
using OutOfRangeViolation= synthetic_exception< struct out_of_range_throwable, Violation, OutOfRangeException >;
|
using OutOfRangeViolation= create_exception< struct out_of_range_throwable, Violation, OutOfRangeException >;
|
||||||
using AnyTaggedOutOfRangeViolation= OutOfRangeViolation::any_tagged_type;
|
using AnyTaggedOutOfRangeViolation= OutOfRangeViolation::any_tagged_type;
|
||||||
template< typename tag >
|
template< typename tag >
|
||||||
using TaggedOutOfRangeViolation= OutOfRangeViolation::tagged_type< tag >;
|
using TaggedOutOfRangeViolation= OutOfRangeViolation::tagged_type< tag >;
|
||||||
@ -380,26 +402,26 @@ namespace Alepha::Hydrogen ::detail:: Exception_m
|
|||||||
std::size_t requested() const noexcept override { return request; }
|
std::size_t requested() const noexcept override { return request; }
|
||||||
};
|
};
|
||||||
class IndexOutOfRangeException
|
class IndexOutOfRangeException
|
||||||
: virtual public synthetic_exception< struct index_out_of_range_throwable, Exception, OutOfRangeException > {};
|
: virtual public create_exception< struct index_out_of_range_throwable, Exception, OutOfRangeException > {};
|
||||||
using AnyTaggedIndexOutOfRangeException= IndexOutOfRangeException::any_tagged_type;
|
using AnyTaggedIndexOutOfRangeException= IndexOutOfRangeException::any_tagged_type;
|
||||||
template< typename tag >
|
template< typename tag >
|
||||||
using TaggedIndexOutOfRangeException= IndexOutOfRangeException::tagged_type< tag >;
|
using TaggedIndexOutOfRangeException= IndexOutOfRangeException::tagged_type< tag >;
|
||||||
|
|
||||||
class IndexOutOfRangeError
|
class IndexOutOfRangeError
|
||||||
: virtual public synthetic_exception< struct index_out_of_range_throwable, OutOfRangeError, IndexOutOfRangeException > {};
|
: virtual public create_exception< struct index_out_of_range_throwable, Error, OutOfRangeError, IndexOutOfRangeException > {};
|
||||||
using AnyTaggedIndexOutOfRangeException= IndexOutOfRangeException::any_tagged_type;
|
using AnyTaggedIndexOutOfRangeException= IndexOutOfRangeException::any_tagged_type;
|
||||||
template< typename tag >
|
template< typename tag >
|
||||||
using TaggedIndexOutOfRangeException= IndexOutOfRangeException::tagged_type< tag >;
|
using TaggedIndexOutOfRangeException= IndexOutOfRangeException::tagged_type< tag >;
|
||||||
|
|
||||||
class IndexOutOfRangeCriticalError
|
class IndexOutOfRangeCriticalError
|
||||||
: virtual public synthetic_exception< struct index_out_of_range_throwable, OutOfRangeCriticalError, IndexOutOfRangeException > {};
|
: virtual public create_exception< struct index_out_of_range_throwable, CriticalError, OutOfRangeCriticalError, IndexOutOfRangeException > {};
|
||||||
using AnyTaggedIndexOutOfRangeCriticalError= IndexOutOfRangeCriticalError::any_tagged_type;
|
using AnyTaggedIndexOutOfRangeCriticalError= IndexOutOfRangeCriticalError::any_tagged_type;
|
||||||
template< typename tag >
|
template< typename tag >
|
||||||
using TaggedIndexOutOfRangeCriticalError= IndexOutOfRangeCriticalError::tagged_type< tag >;
|
using TaggedIndexOutOfRangeCriticalError= IndexOutOfRangeCriticalError::tagged_type< tag >;
|
||||||
|
|
||||||
|
|
||||||
class IndexOutOfRangeViolation
|
class IndexOutOfRangeViolation
|
||||||
: virtual public synthetic_exception< struct index_out_of_range_throwable, OutOfRangeViolation, IndexOutOfRangeException > {};
|
: virtual public create_exception< struct index_out_of_range_throwable, Violation, OutOfRangeViolation, IndexOutOfRangeException > {};
|
||||||
using AnyTaggedIndexOutOfRangeViolation= IndexOutOfRangeViolation::any_tagged_type;
|
using AnyTaggedIndexOutOfRangeViolation= IndexOutOfRangeViolation::any_tagged_type;
|
||||||
template< typename tag >
|
template< typename tag >
|
||||||
using TaggedIndexOutOfRangeViolation= IndexOutOfRangeViolation::tagged_type< tag >;
|
using TaggedIndexOutOfRangeViolation= IndexOutOfRangeViolation::tagged_type< tag >;
|
||||||
@ -423,22 +445,22 @@ namespace Alepha::Hydrogen ::detail:: Exception_m
|
|||||||
std::size_t allocationAmount() const noexcept final { return amount; }
|
std::size_t allocationAmount() const noexcept final { return amount; }
|
||||||
};
|
};
|
||||||
class AllocationException
|
class AllocationException
|
||||||
: virtual public synthetic_exception< struct allocation_throwable, Exception >, virtual public AllocationAmountInterface {};
|
: virtual public create_exception< struct allocation_throwable, Exception >, virtual public AllocationAmountInterface {};
|
||||||
using AnyTaggedAllocationException= AllocationException::any_tagged_type;
|
using AnyTaggedAllocationException= AllocationException::any_tagged_type;
|
||||||
template< typename tag >
|
template< typename tag >
|
||||||
using TaggedAllocationException= AllocationException::tagged_type< tag >;
|
using TaggedAllocationException= AllocationException::tagged_type< tag >;
|
||||||
|
|
||||||
using AllocationError= synthetic_exception< struct allocation_exception, Error, AllocationException >;
|
using AllocationError= create_exception< struct allocation_exception, Error, AllocationException >;
|
||||||
using AnyTaggedAllocationError= AllocationError::any_tagged_type;
|
using AnyTaggedAllocationError= AllocationError::any_tagged_type;
|
||||||
template< typename tag >
|
template< typename tag >
|
||||||
using TaggedAllocationError= AllocationError::tagged_type< tag >;
|
using TaggedAllocationError= AllocationError::tagged_type< tag >;
|
||||||
|
|
||||||
using AllocationCriticalError= synthetic_exception< struct allocation_error, CriticalError, AllocationException >;
|
using AllocationCriticalError= create_exception< struct allocation_error, CriticalError, AllocationException >;
|
||||||
using AnyTaggedAllocationCriticalError= AllocationCriticalError::any_tagged_type;
|
using AnyTaggedAllocationCriticalError= AllocationCriticalError::any_tagged_type;
|
||||||
template< typename tag >
|
template< typename tag >
|
||||||
using TaggedAllocationCriticalError= AllocationCriticalError::tagged_type< tag >;
|
using TaggedAllocationCriticalError= AllocationCriticalError::tagged_type< tag >;
|
||||||
|
|
||||||
using AllocationViolation= synthetic_exception< struct allocation_violation, Violation, AllocationException >;
|
using AllocationViolation= create_exception< struct allocation_violation, Violation, AllocationException >;
|
||||||
using AnyTaggedAllocationViolation= AllocationViolation::any_tagged_type;
|
using AnyTaggedAllocationViolation= AllocationViolation::any_tagged_type;
|
||||||
template< typename tag >
|
template< typename tag >
|
||||||
using TaggedAllocationViolation= AllocationViolation::tagged_type< tag >;
|
using TaggedAllocationViolation= AllocationViolation::tagged_type< tag >;
|
||||||
@ -542,11 +564,11 @@ namespace Alepha::Hydrogen ::detail:: Exception_m
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
using FinishedException= synthetic_exception< struct finished_exception, Exception >;
|
using FinishedException= create_exception< struct finished_exception, Exception >;
|
||||||
using AnyTaggedFinishedException= AnyTagged< FinishedException >;
|
using AnyTaggedFinishedException= AnyTagged< FinishedException >;
|
||||||
template< typename tag > using TaggedFinishedException= Tagged< FinishedException, tag >;
|
template< typename tag > using TaggedFinishedException= Tagged< FinishedException, tag >;
|
||||||
|
|
||||||
using FinishedCondition= synthetic_exception< struct finished_exception, Condition, FinishedException >;
|
using FinishedCondition= create_exception< struct finished_condition, Condition, FinishedException >;
|
||||||
using AnyTaggedFinishedCondition= AnyTagged< FinishedCondition >;
|
using AnyTaggedFinishedCondition= AnyTagged< FinishedCondition >;
|
||||||
template< typename tag > using TaggedFinishedCondition= Tagged< FinishedCondition, tag >;
|
template< typename tag > using TaggedFinishedCondition= Tagged< FinishedCondition, tag >;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user