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