Exceptions

Shared exception types and source-location information.

enum class snt::core::DiagnosticSeverity

Values:

enumerator Info
enumerator Warning
enumerator Error
struct Diagnostic
#include <diagnostic.h>

Structured diagnostic for CLI, tests, and interactive clients.

Public Members

DiagnosticSeverity severity
std::string code

Stable category, such as “dip.syntax”.

std::string message
std::string details
std::string suggestion
std::optional<std::string> node_path
std::optional<SourceLocation> location

User input location, when known.

std::optional<SourceLocation> origin

Implementation location, when known.

class Exception : public snt::core::ExceptionBase<ExceptionInfo>
#include <exceptions.h>

Base exception type for errors raised by the core library.

Subclassed by snt::api::Exception, snt::core::MissingException, snt::core::ParserException, snt::exs::Exception, snt::mat::Exception, snt::puq::Exception, snt::val::Exception

Public Functions

inline Exception(std::string message, std::string details, std::string suggestion, std::string origin_file, size_t origin_line)

Construct an exception with message, details, suggestion, and source location.

template<typename E>
class ExceptionBase : public std::runtime_error
#include <exceptions.h>

Public Functions

inline explicit ExceptionBase(E info, std::string prefix = "[SNT-CORE] ")

Construct an exception from structured information and an optional display prefix.

inline const char *what() const noexcept override

Return the fully formatted diagnostic text.

inline const E &info() const noexcept

Return the structured exception information.

struct ExceptionInfo
#include <exceptions.h>

Structured information carried by an SNT exception.

Subclassed by snt::dip::ExceptionInfo

Public Members

std::string message

Exception message.

std::string details

Details error description.

std::string suggestion

Suggested changes.

std::optional<SourceLocation> origin

Where the error was thrown in the source.

class MissingException : public snt::core::Exception
#include <exceptions.h>

Missing exception is triggered when functionality is not implemented yet Exception raised when requested functionality is unavailable.

Public Functions

inline MissingException(std::string message, std::string file, std::size_t line)

Construct an exception identifying unavailable functionality.

class ParserException : public snt::core::Exception
#include <exceptions.h>

Parse exceptions are triggered during parsing Exception raised while parsing input.

struct SourceLocation
#include <exceptions.h>

Source location associated with a diagnostic.

Public Members

std::string source

Source file or input name.

std::size_t line

One-based source line, or zero when unavailable.

std::optional<std::string> code

Source text associated with the location.

std::optional<std::size_t> column

Optional one-based source column.