A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
fatal-example.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2020 Lawrence Livermore National Laboratory
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Peter D. Barnes, Jr. <pdbarnes@llnl.gov>
7 */
8
9#include "ns3/assert.h"
10#include "ns3/fatal-error.h"
11#include "ns3/simulator.h"
12
13#include <iostream>
14
15/**
16 * \file
17 * \defgroup fatal-example Core example: NS_FATAL error handlers
18 * \ingroup core-examples
19 * \ingroup fatal
20 *
21 * Example program illustrating use of the NS_FATAL error handlers.
22 */
23
24using namespace ns3;
25
26/**
27 * \ingroup fatal-example
28 * \brief Triggers a fatal error without message, deferring termination.
29 */
30void
32{
33 std::cerr << "\nEvent triggered fatal error without message, and continuing:" << std::endl;
35}
36
37/**
38 * \ingroup fatal-example
39 * \brief Triggers a fatal error with an error message, deferring termination.
40 */
41void
43{
44 std::cerr << "\nEvent triggered fatal error, with custom message, and continuing:" << std::endl;
45 NS_FATAL_ERROR_CONT("fatal error, but continuing");
46}
47
48/**
49 * \ingroup fatal-example
50 * \brief Triggers a fatal error with message, and terminating.
51 */
52void
54{
55 std::cerr << "\nEvent triggered fatal error, with message, and terminating:" << std::endl;
56 NS_FATAL_ERROR("fatal error, terminating");
57}
58
59int
60main(int argc, char** argv)
61{
62 // First schedule some events
66
67 // Show some errors outside of simulation time
68 std::cerr << "\nFatal error with custom message, and continuing:" << std::endl;
69 NS_FATAL_ERROR_CONT("fatal error, but continuing");
70
71 std::cerr << "\nFatal error without message, and continuing:" << std::endl;
73
74 // Now run the simulator
76
77 // Should not get here
78 NS_FATAL_ERROR("fatal error, terminating");
79 NS_ASSERT_MSG(false, "Should not get here.");
80
81 return 0;
82}
static EventId Schedule(const Time &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
Definition simulator.h:560
static void Run()
Run the simulation.
Definition simulator.cc:167
#define NS_ASSERT_MSG(condition, message)
At runtime, in debugging builds, if this condition is not true, the program prints the message to out...
Definition assert.h:75
void FatalCont()
Triggers a fatal error with an error message, deferring termination.
void Fatal()
Triggers a fatal error with message, and terminating.
void FatalNoMsg()
Triggers a fatal error without message, deferring termination.
#define NS_FATAL_ERROR_CONT(msg)
Report a fatal error with a message, deferring termination.
#define NS_FATAL_ERROR_NO_MSG_CONT()
Report a fatal error, deferring termination.
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition nstime.h:1308
Every class exported by the ns3 library is enclosed in the ns3 namespace.