A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Documentation ▼
Installation
Manual
Models
Contributing
Wiki
Development ▼
API Docs
Issue Tracker
Merge Requests
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
24
using namespace
ns3
;
25
26
/**
27
* \ingroup fatal-example
28
* \brief Triggers a fatal error without message, deferring termination.
29
*/
30
void
31
FatalNoMsg
()
32
{
33
std::cerr <<
"\nEvent triggered fatal error without message, and continuing:"
<< std::endl;
34
NS_FATAL_ERROR_NO_MSG_CONT
();
35
}
36
37
/**
38
* \ingroup fatal-example
39
* \brief Triggers a fatal error with an error message, deferring termination.
40
*/
41
void
42
FatalCont
()
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
*/
52
void
53
Fatal
()
54
{
55
std::cerr <<
"\nEvent triggered fatal error, with message, and terminating:"
<< std::endl;
56
NS_FATAL_ERROR
(
"fatal error, terminating"
);
57
}
58
59
int
60
main(
int
argc,
char
** argv)
61
{
62
// First schedule some events
63
Simulator::Schedule
(
Seconds
(1),
FatalNoMsg
);
64
Simulator::Schedule
(
Seconds
(2),
FatalCont
);
65
Simulator::Schedule
(
Seconds
(3),
Fatal
);
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;
72
NS_FATAL_ERROR_NO_MSG_CONT
();
73
74
// Now run the simulator
75
Simulator::Run
();
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
}
ns3::Simulator::Schedule
static EventId Schedule(const Time &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
Definition
simulator.h:560
ns3::Simulator::Run
static void Run()
Run the simulation.
Definition
simulator.cc:167
NS_ASSERT_MSG
#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
FatalCont
void FatalCont()
Triggers a fatal error with an error message, deferring termination.
Definition
fatal-example.cc:42
Fatal
void Fatal()
Triggers a fatal error with message, and terminating.
Definition
fatal-example.cc:53
FatalNoMsg
void FatalNoMsg()
Triggers a fatal error without message, deferring termination.
Definition
fatal-example.cc:31
NS_FATAL_ERROR_CONT
#define NS_FATAL_ERROR_CONT(msg)
Report a fatal error with a message, deferring termination.
Definition
fatal-error.h:184
NS_FATAL_ERROR_NO_MSG_CONT
#define NS_FATAL_ERROR_NO_MSG_CONT()
Report a fatal error, deferring termination.
Definition
fatal-error.h:147
NS_FATAL_ERROR
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
Definition
fatal-error.h:168
ns3::Seconds
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition
nstime.h:1308
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
src
core
examples
fatal-example.cc
Generated on Fri Nov 8 2024 13:58:59 for ns-3 by
1.11.0