A Discrete-Event Network Simulator
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 
34 using namespace ns3;
35 
36 void
37 FatalNoMsg (void)
38 {
39  std::cerr << "\nEvent triggered fatal error without message, and continuing:"
40  << std::endl;
42 }
43 
44 void
45 FatalCont (void)
46 {
47  std::cerr << "\nEvent triggered fatal error, with custom message, and continuing:"
48  << std::endl;
49  NS_FATAL_ERROR_CONT ("fatal error, but continuing");
50 }
51 
52 void
53 Fatal (void)
54 {
55  std::cerr << "\nEvent triggered fatal error, with message, and terminating:"
56  << std::endl;
57  NS_FATAL_ERROR ("fatal error, terminating");
58 }
59 
60 int
61 main (int argc, char ** argv)
62 {
63  // First schedule some events
67 
68 
69  // Show some errors outside of simulation time
70  std::cerr << "\nFatal error with custom message, and continuing:" << std::endl;
71  NS_FATAL_ERROR_CONT ("fatal error, but continuing");
72 
73  std::cerr << "\nFatal error without message, and continuing:" << std::endl;
75 
76  // Now run the simulator
77  Simulator::Run ();
78 
79  // Should not get here
80  NS_FATAL_ERROR ("fatal error, terminating");
81  NS_ASSERT_MSG (false, "Should not get here.");
82 
83  return 0;
84 }
FatalNoMsg
void FatalNoMsg(void)
Definition: fatal-example.cc:37
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
NS_FATAL_ERROR_CONT
#define NS_FATAL_ERROR_CONT(msg)
Report a fatal error with a message, deferring termination.
Definition: fatal-error.h:181
ns3::Simulator::Schedule
static EventId Schedule(Time const &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
Definition: simulator.h:556
NS_FATAL_ERROR
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
Definition: fatal-error.h:165
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
ns3::Simulator::Run
static void Run(void)
Run the simulation.
Definition: simulator.cc:172
ns3::Seconds
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1289
FatalCont
void FatalCont(void)
Definition: fatal-example.cc:45
Fatal
void Fatal(void)
Definition: fatal-example.cc:53
NS_FATAL_ERROR_NO_MSG_CONT
#define NS_FATAL_ERROR_NO_MSG_CONT()
Report a fatal error, deferring termination.
Definition: fatal-error.h:144