svMultiPhysics
Loading...
Searching...
No Matches
Public Member Functions | List of all members
svmp::Diagnostic Class Reference

A diagnostic message bundled with the source location where it was written. More...

#include <Exception.h>

Public Member Functions

 Diagnostic (const char *message, const char *file=__builtin_FILE(), int line=__builtin_LINE(), const char *function=__builtin_FUNCTION())
 Wrap a message, capturing the caller's source location by default.
 
 Diagnostic (std::string message, const char *file=__builtin_FILE(), int line=__builtin_LINE(), const char *function=__builtin_FUNCTION())
 Wrap a message, capturing the caller's source location by default.
 
const std::string & message () const noexcept
 The diagnostic message.
 
const SourceLocation & location () const noexcept
 The source location captured when the Diagnostic was constructed.
 

Detailed Description

A diagnostic message bundled with the source location where it was written.

The core helpers (raise(), check(), throw_if(), check_not_null()) take a Diagnostic in place of an explicit source location. Its file/line/function arguments default to the compiler builtins __builtin_FILE()/__builtin_LINE()/ __builtin_FUNCTION(), which capture the caller's location, so a string literal or std::string passed at the call site is implicitly wrapped into a Diagnostic that records exactly where the call appears – callers pass no explicit location:

svmp::check<MyException>(ptr != nullptr, "pointer must not be null");

Constructor & Destructor Documentation

◆ Diagnostic() [1/2]

svmp::Diagnostic::Diagnostic ( const char *  message,
const char *  file = __builtin_FILE(),
int  line = __builtin_LINE(),
const char *  function = __builtin_FUNCTION() 
)
inline

Wrap a message, capturing the caller's source location by default.

Parameters
messageThe diagnostic message.
fileSource file; defaults to the caller's via __builtin_FILE().
lineSource line; defaults to the caller's via __builtin_LINE().
functionFunction; defaults to the caller's via __builtin_FUNCTION().

◆ Diagnostic() [2/2]

svmp::Diagnostic::Diagnostic ( std::string  message,
const char *  file = __builtin_FILE(),
int  line = __builtin_LINE(),
const char *  function = __builtin_FUNCTION() 
)
inline

Wrap a message, capturing the caller's source location by default.

Parameters
messageThe diagnostic message.
fileSource file; defaults to the caller's via __builtin_FILE().
lineSource line; defaults to the caller's via __builtin_LINE().
functionFunction; defaults to the caller's via __builtin_FUNCTION().

Member Function Documentation

◆ location()

const SourceLocation & svmp::Diagnostic::location ( ) const
inlinenoexcept

The source location captured when the Diagnostic was constructed.

Returns
The stored source location.

◆ message()

const std::string & svmp::Diagnostic::message ( ) const
inlinenoexcept

The diagnostic message.

Returns
The stored message.

The documentation for this class was generated from the following file: