Rosetta
Classes | Namespaces | Macros | Typedefs | Functions
exit.hh File Reference

Program exit functions and macros. More...

#include <string>
#include <utility/cxx_versioning_macros.hh>

Classes

class  utility_exit_detail::Stringy
 
class  utility_exit_detail::Stringifier
 

Namespaces

 utility_exit_detail
 
 utility
 unresizable vector whose size is known at compile time, which may be allocated on the stack, and which indexes from 0.
 

Macros

#define user_fixable_issue_exit(...)   utility::exit_with_user_fixable_issue( __FILE__, __LINE__, utility_exit_detail::Stringifier{ __VA_ARGS__ }.get_string() )
 Macro for an exit with an issue which doesn't trigger the crash reporter system These need to have parameters, which are used to create the user message. More...
 
#define user_fixable_issue_assert(_Expression, ...)    if ( !(_Expression) ) utility::exit_with_user_fixable_issue(__FILE__, __LINE__, utility_exit_detail::Stringifier{ __VA_ARGS__ }.get_string() )
 
#define utility_exit()   utility::exit( __FILE__, __LINE__ )
 Macro function wrappers for utility::exit. More...
 
#define utility_exit_with_message(m)   utility::exit( __FILE__, __LINE__, m )
 Exit with file + line + message. More...
 
#define utility_exit_with_status(s)   utility::exit( __FILE__, __LINE__, s )
 Exit with file + line + status. More...
 
#define utility_exit_with_message_status(m, s)   utility::exit( __FILE__, __LINE__, m, s )
 Exit with file + line + message + status. More...
 
#define runtime_assert(_Expression)   if ( !(_Expression) ) utility::exit(__FILE__, __LINE__, "Assertion `" #_Expression "` failed.")
 Assert that the condition holds. Evaluated for both debug and release builds. More...
 
#define runtime_assert_msg(_Expression, msg)    if ( !(_Expression) ) utility::exit(__FILE__, __LINE__, "Assertion `" #_Expression "` failed. MSG:" msg )
 Assert that the condition holds. Evaluated for both debug and release builds. More...
 
#define runtime_assert_string_msg(_Expression, msg)    if ( !(_Expression) ) utility::exit(__FILE__, __LINE__, msg )
 Assert that the condition holds. Evaluated for both debug and release builds. More...
 

Typedefs

typedef void(* utility::UtilityExitCallBack) ()
 

Functions

void utility::exit_with_user_fixable_issue (char const *file, int line, std::string const &message)
 Exit in cases where there's a clear issue the user can fix. More...
 
void utility::exit (char const *file, int const line, std::string const &message, int const)
 Exit with file + line + message + optional status. More...
 
int utility::cond_exit (bool condition, char const *file, int const line, std::string const &message, int const status)
 Conditional Exit with file + line + message + optional status. More...
 
NORETURN_ATTR void utility::exit (char const *file, int const line, int const status=1)
 Exit with file + line + optional status. More...
 
void utility::exit (int const status, char const *file, int const line)
 Exit with file + line + status. More...
 
void utility::set_main_exit_callback (UtilityExitCallBack=nullptr)
 Set call back funtion that will be called on utility::exit. Use this function to overload default behavior of sys.exit to more appropriate to your application Defaut value for callback function is nullptr, whicth mean no sys exit is called. More...
 
void utility::add_exit_callback (UtilityExitCallBack)
 Add additional callback function that will be called before standard exit(…) is executed. [Note: do not confuse this function with 'set_main_exit_callback' which is replacing the end behavior of exit(…)]. More...
 
void utility::remove_exit_callback (UtilityExitCallBack)
 Remove additional callback function that was previously added by using add_exit_callback. More...
 

Detailed Description

Program exit functions and macros.

Author
David Kim (dekim.nosp@m.@u.w.nosp@m.ashin.nosp@m.gton.nosp@m..edu)
Sergey Lyskov (Serge.nosp@m.y.Ly.nosp@m.skov@.nosp@m.jhu..nosp@m.edu)
Stuart G. Mentzer (Stuar.nosp@m.t_Me.nosp@m.ntzer.nosp@m.@obj.nosp@m.exx.c.nosp@m.om)
Note
The point of these is:
  • Show the file and line number where the exit originates
  • Optionally show a message about why the exit occurred
  • Provide a core dump on Linux/UNIX so a post-mortem backtrace can be performed
  • Provide macro functions to add the file and line for you
Break on utility::exit when debugging to allow you to get a backtrace from the point of exit

Macro Definition Documentation

◆ runtime_assert

#define runtime_assert (   _Expression)    if ( !(_Expression) ) utility::exit(__FILE__, __LINE__, "Assertion `" #_Expression "` failed.")

Assert that the condition holds. Evaluated for both debug and release builds.

◆ runtime_assert_msg

#define runtime_assert_msg (   _Expression,
  msg 
)     if ( !(_Expression) ) utility::exit(__FILE__, __LINE__, "Assertion `" #_Expression "` failed. MSG:" msg )

Assert that the condition holds. Evaluated for both debug and release builds.

◆ runtime_assert_string_msg

#define runtime_assert_string_msg (   _Expression,
  msg 
)     if ( !(_Expression) ) utility::exit(__FILE__, __LINE__, msg )

Assert that the condition holds. Evaluated for both debug and release builds.

◆ user_fixable_issue_assert

#define user_fixable_issue_assert (   _Expression,
  ... 
)     if ( !(_Expression) ) utility::exit_with_user_fixable_issue(__FILE__, __LINE__, utility_exit_detail::Stringifier{ __VA_ARGS__ }.get_string() )

◆ user_fixable_issue_exit

#define user_fixable_issue_exit (   ...)    utility::exit_with_user_fixable_issue( __FILE__, __LINE__, utility_exit_detail::Stringifier{ __VA_ARGS__ }.get_string() )

Macro for an exit with an issue which doesn't trigger the crash reporter system These need to have parameters, which are used to create the user message.

As a convenience, you can pass multiple parameters to these macros, all of which will be stringified and concatenated into the message. E.g.:

user_fixable_issue_exit( "Loops file `", filename, "` has only ", num_entry, " entries on line ", lineno, ". It needs at least 3.");

Note
Since C++11, variadic macros are part of C++

◆ utility_exit

#define utility_exit ( )    utility::exit( __FILE__, __LINE__ )

Macro function wrappers for utility::exit.

Note
Convenience macros that fills in the file and line
These have to be macros to get the file and line from the point of call

Exit with file + line

◆ utility_exit_with_message

#define utility_exit_with_message (   m)    utility::exit( __FILE__, __LINE__, m )

Exit with file + line + message.

Note
The m argument is a message string

◆ utility_exit_with_message_status

#define utility_exit_with_message_status (   m,
 
)    utility::exit( __FILE__, __LINE__, m, s )

Exit with file + line + message + status.

Note
The m argument is a message string
The s argument is a status value

◆ utility_exit_with_status

#define utility_exit_with_status (   s)    utility::exit( __FILE__, __LINE__, s )

Exit with file + line + status.

Note
The s argument is a status value