A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Documentation ▼
Installation
Manual
Models
Contributing
Wiki
Development ▼
API Docs
Issue Tracker
Merge Requests
API
fatal-example.cc
Go to the documentation of this file.
1
/*
2
* Copyright (c) 2020 Lawrence Livermore National Laboratory
3
*
4
* This program is free software; you can redistribute it and/or modify
5
* it under the terms of the GNU General Public License version 2 as
6
* published by the Free Software Foundation;
7
*
8
* This program is distributed in the hope that it will be useful,
9
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
* GNU General Public License for more details.
12
*
13
* You should have received a copy of the GNU General Public License
14
* along with this program; if not, write to the Free Software
15
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16
*
17
* Author: Peter D. Barnes, Jr. <pdbarnes@llnl.gov>
18
*/
19
20
#include "ns3/assert.h"
21
#include "ns3/fatal-error.h"
22
#include "ns3/simulator.h"
23
24
#include <iostream>
25
35
using namespace
ns3
;
36
41
void
42
FatalNoMsg
()
43
{
44
std::cerr <<
"\nEvent triggered fatal error without message, and continuing:"
<< std::endl;
45
NS_FATAL_ERROR_NO_MSG_CONT
();
46
}
47
52
void
53
FatalCont
()
54
{
55
std::cerr <<
"\nEvent triggered fatal error, with custom message, and continuing:"
<< std::endl;
56
NS_FATAL_ERROR_CONT
(
"fatal error, but continuing"
);
57
}
58
63
void
64
Fatal
()
65
{
66
std::cerr <<
"\nEvent triggered fatal error, with message, and terminating:"
<< std::endl;
67
NS_FATAL_ERROR
(
"fatal error, terminating"
);
68
}
69
70
int
71
main(
int
argc,
char
** argv)
72
{
73
// First schedule some events
74
Simulator::Schedule
(
Seconds
(1),
FatalNoMsg
);
75
Simulator::Schedule
(
Seconds
(2),
FatalCont
);
76
Simulator::Schedule
(
Seconds
(3),
Fatal
);
77
78
// Show some errors outside of simulation time
79
std::cerr <<
"\nFatal error with custom message, and continuing:"
<< std::endl;
80
NS_FATAL_ERROR_CONT
(
"fatal error, but continuing"
);
81
82
std::cerr <<
"\nFatal error without message, and continuing:"
<< std::endl;
83
NS_FATAL_ERROR_NO_MSG_CONT
();
84
85
// Now run the simulator
86
Simulator::Run
();
87
88
// Should not get here
89
NS_FATAL_ERROR
(
"fatal error, terminating"
);
90
NS_ASSERT_MSG
(
false
,
"Should not get here."
);
91
92
return
0;
93
}
ns3::Simulator::Schedule
static EventId Schedule(const Time &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
Definition:
simulator.h:571
ns3::Simulator::Run
static void Run()
Run the simulation.
Definition:
simulator.cc:178
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:86
FatalCont
void FatalCont()
Triggers a fatal error with an error message, deferring termination.
Definition:
fatal-example.cc:53
Fatal
void Fatal()
Triggers a fatal error with message, and terminating.
Definition:
fatal-example.cc:64
FatalNoMsg
void FatalNoMsg()
Triggers a fatal error without message, deferring termination.
Definition:
fatal-example.cc:42
NS_FATAL_ERROR_CONT
#define NS_FATAL_ERROR_CONT(msg)
Report a fatal error with a message, deferring termination.
Definition:
fatal-error.h:195
NS_FATAL_ERROR_NO_MSG_CONT
#define NS_FATAL_ERROR_NO_MSG_CONT()
Report a fatal error, deferring termination.
Definition:
fatal-error.h:158
NS_FATAL_ERROR
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
Definition:
fatal-error.h:179
ns3::Seconds
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition:
nstime.h:1326
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
src
core
examples
fatal-example.cc
Generated on Sun Mar 3 2024 17:10:55 for ns-3 by
1.9.1