src/core/model/fatal-error.h
author Josh Pelkey <jpelkey@gatech.edu>
Fri, 13 May 2011 14:52:27 -0400
changeset 7169 358f71a624d8
parent 6821 203367ae7433
child 7256 b04ba6772f8c
permissions -rw-r--r--
core coding style changes
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
278
fc1133fee95d add fatal-error.h header
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
fc1133fee95d add fatal-error.h header
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     2
/*
6370
0a0b6bf5fdfd bug 933: Flushing ostream and files on abnormal program exit
Quincy Tse <quincy.tse@gmail.com>
parents: 3492
diff changeset
     3
 * Copyright (c) 2006 INRIA, 2010 NICTA
278
fc1133fee95d add fatal-error.h header
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     4
 *
fc1133fee95d add fatal-error.h header
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     5
 * This program is free software; you can redistribute it and/or modify
fc1133fee95d add fatal-error.h header
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     6
 * it under the terms of the GNU General Public License version 2 as
fc1133fee95d add fatal-error.h header
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     7
 * published by the Free Software Foundation;
fc1133fee95d add fatal-error.h header
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     8
 *
fc1133fee95d add fatal-error.h header
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
fc1133fee95d add fatal-error.h header
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
fc1133fee95d add fatal-error.h header
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
fc1133fee95d add fatal-error.h header
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    12
 * GNU General Public License for more details.
fc1133fee95d add fatal-error.h header
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    13
 *
fc1133fee95d add fatal-error.h header
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    14
 * You should have received a copy of the GNU General Public License
fc1133fee95d add fatal-error.h header
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    15
 * along with this program; if not, write to the Free Software
fc1133fee95d add fatal-error.h header
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    16
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
fc1133fee95d add fatal-error.h header
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    17
 *
fc1133fee95d add fatal-error.h header
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    18
 * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
6370
0a0b6bf5fdfd bug 933: Flushing ostream and files on abnormal program exit
Quincy Tse <quincy.tse@gmail.com>
parents: 3492
diff changeset
    19
 *         Quincy Tse <quincy.tse@nicta.com.au>
278
fc1133fee95d add fatal-error.h header
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    20
 */
6370
0a0b6bf5fdfd bug 933: Flushing ostream and files on abnormal program exit
Quincy Tse <quincy.tse@gmail.com>
parents: 3492
diff changeset
    21
#ifndef NS3_FATAL_ERROR_H
0a0b6bf5fdfd bug 933: Flushing ostream and files on abnormal program exit
Quincy Tse <quincy.tse@gmail.com>
parents: 3492
diff changeset
    22
#define NS3_FATAL_ERROR_H
278
fc1133fee95d add fatal-error.h header
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    23
391
0b920298da18 make sure we include std::cout definition even in optimized builds
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 345
diff changeset
    24
#include <iostream>
6370
0a0b6bf5fdfd bug 933: Flushing ostream and files on abnormal program exit
Quincy Tse <quincy.tse@gmail.com>
parents: 3492
diff changeset
    25
#include <exception>
0a0b6bf5fdfd bug 933: Flushing ostream and files on abnormal program exit
Quincy Tse <quincy.tse@gmail.com>
parents: 3492
diff changeset
    26
#include <cstdlib>
0a0b6bf5fdfd bug 933: Flushing ostream and files on abnormal program exit
Quincy Tse <quincy.tse@gmail.com>
parents: 3492
diff changeset
    27
0a0b6bf5fdfd bug 933: Flushing ostream and files on abnormal program exit
Quincy Tse <quincy.tse@gmail.com>
parents: 3492
diff changeset
    28
#include "fatal-impl.h"
0a0b6bf5fdfd bug 933: Flushing ostream and files on abnormal program exit
Quincy Tse <quincy.tse@gmail.com>
parents: 3492
diff changeset
    29
0a0b6bf5fdfd bug 933: Flushing ostream and files on abnormal program exit
Quincy Tse <quincy.tse@gmail.com>
parents: 3492
diff changeset
    30
/**
0a0b6bf5fdfd bug 933: Flushing ostream and files on abnormal program exit
Quincy Tse <quincy.tse@gmail.com>
parents: 3492
diff changeset
    31
 * \ingroup debugging
0a0b6bf5fdfd bug 933: Flushing ostream and files on abnormal program exit
Quincy Tse <quincy.tse@gmail.com>
parents: 3492
diff changeset
    32
 * \brief fatal error handling
0a0b6bf5fdfd bug 933: Flushing ostream and files on abnormal program exit
Quincy Tse <quincy.tse@gmail.com>
parents: 3492
diff changeset
    33
 *
0a0b6bf5fdfd bug 933: Flushing ostream and files on abnormal program exit
Quincy Tse <quincy.tse@gmail.com>
parents: 3492
diff changeset
    34
 * When this macro is hit at runtime, details of filename
0a0b6bf5fdfd bug 933: Flushing ostream and files on abnormal program exit
Quincy Tse <quincy.tse@gmail.com>
parents: 3492
diff changeset
    35
 * and line number is printed to stderr, and the program
0a0b6bf5fdfd bug 933: Flushing ostream and files on abnormal program exit
Quincy Tse <quincy.tse@gmail.com>
parents: 3492
diff changeset
    36
 * is halted by calling std::terminate(). This will
0a0b6bf5fdfd bug 933: Flushing ostream and files on abnormal program exit
Quincy Tse <quincy.tse@gmail.com>
parents: 3492
diff changeset
    37
 * trigger any clean up code registered by
0a0b6bf5fdfd bug 933: Flushing ostream and files on abnormal program exit
Quincy Tse <quincy.tse@gmail.com>
parents: 3492
diff changeset
    38
 * std::set_terminate (NS3 default is a stream-flushing
0a0b6bf5fdfd bug 933: Flushing ostream and files on abnormal program exit
Quincy Tse <quincy.tse@gmail.com>
parents: 3492
diff changeset
    39
 * code), but may be overridden.
0a0b6bf5fdfd bug 933: Flushing ostream and files on abnormal program exit
Quincy Tse <quincy.tse@gmail.com>
parents: 3492
diff changeset
    40
 *
0a0b6bf5fdfd bug 933: Flushing ostream and files on abnormal program exit
Quincy Tse <quincy.tse@gmail.com>
parents: 3492
diff changeset
    41
 * This macro is enabled unconditionally in all builds,
0a0b6bf5fdfd bug 933: Flushing ostream and files on abnormal program exit
Quincy Tse <quincy.tse@gmail.com>
parents: 3492
diff changeset
    42
 * including debug and optimized builds.
0a0b6bf5fdfd bug 933: Flushing ostream and files on abnormal program exit
Quincy Tse <quincy.tse@gmail.com>
parents: 3492
diff changeset
    43
 */
0a0b6bf5fdfd bug 933: Flushing ostream and files on abnormal program exit
Quincy Tse <quincy.tse@gmail.com>
parents: 3492
diff changeset
    44
#define NS_FATAL_ERROR_NO_MSG()                           \
0a0b6bf5fdfd bug 933: Flushing ostream and files on abnormal program exit
Quincy Tse <quincy.tse@gmail.com>
parents: 3492
diff changeset
    45
  do                                                      \
0a0b6bf5fdfd bug 933: Flushing ostream and files on abnormal program exit
Quincy Tse <quincy.tse@gmail.com>
parents: 3492
diff changeset
    46
    {                                                     \
0a0b6bf5fdfd bug 933: Flushing ostream and files on abnormal program exit
Quincy Tse <quincy.tse@gmail.com>
parents: 3492
diff changeset
    47
      std::cerr << "file=" << __FILE__ << ", line=" <<    \
7169
358f71a624d8 core coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6821
diff changeset
    48
      __LINE__ << std::endl;                            \
6370
0a0b6bf5fdfd bug 933: Flushing ostream and files on abnormal program exit
Quincy Tse <quincy.tse@gmail.com>
parents: 3492
diff changeset
    49
      ::ns3::FatalImpl::FlushStreams ();                  \
0a0b6bf5fdfd bug 933: Flushing ostream and files on abnormal program exit
Quincy Tse <quincy.tse@gmail.com>
parents: 3492
diff changeset
    50
      std::terminate ();                                  \
0a0b6bf5fdfd bug 933: Flushing ostream and files on abnormal program exit
Quincy Tse <quincy.tse@gmail.com>
parents: 3492
diff changeset
    51
    }                                                     \
0a0b6bf5fdfd bug 933: Flushing ostream and files on abnormal program exit
Quincy Tse <quincy.tse@gmail.com>
parents: 3492
diff changeset
    52
  while (false)
278
fc1133fee95d add fatal-error.h header
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    53
fc1133fee95d add fatal-error.h header
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    54
/**
3182
61fe7fe81ebd Doxygen organization
Tom Henderson <tomh@tomh.org>
parents: 2834
diff changeset
    55
 * \ingroup debugging
278
fc1133fee95d add fatal-error.h header
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    56
 * \brief fatal error handling
fc1133fee95d add fatal-error.h header
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    57
 *
fc1133fee95d add fatal-error.h header
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    58
 * \param msg message to output when this macro is hit.
fc1133fee95d add fatal-error.h header
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    59
 *
6370
0a0b6bf5fdfd bug 933: Flushing ostream and files on abnormal program exit
Quincy Tse <quincy.tse@gmail.com>
parents: 3492
diff changeset
    60
 * When this macro is hit at runtime, the user-specified
0a0b6bf5fdfd bug 933: Flushing ostream and files on abnormal program exit
Quincy Tse <quincy.tse@gmail.com>
parents: 3492
diff changeset
    61
 * error message is printed to stderr, followed by a call
0a0b6bf5fdfd bug 933: Flushing ostream and files on abnormal program exit
Quincy Tse <quincy.tse@gmail.com>
parents: 3492
diff changeset
    62
 * to the NS_FATAL_ERROR_NO_MSG() macro which prints the
0a0b6bf5fdfd bug 933: Flushing ostream and files on abnormal program exit
Quincy Tse <quincy.tse@gmail.com>
parents: 3492
diff changeset
    63
 * details of filename and line number to stderr. The
0a0b6bf5fdfd bug 933: Flushing ostream and files on abnormal program exit
Quincy Tse <quincy.tse@gmail.com>
parents: 3492
diff changeset
    64
 * program will be halted by calling std::terminate(),
0a0b6bf5fdfd bug 933: Flushing ostream and files on abnormal program exit
Quincy Tse <quincy.tse@gmail.com>
parents: 3492
diff changeset
    65
 * triggering any clean up code registered by
0a0b6bf5fdfd bug 933: Flushing ostream and files on abnormal program exit
Quincy Tse <quincy.tse@gmail.com>
parents: 3492
diff changeset
    66
 * std::set_terminate (NS3 default is a stream-flushing
0a0b6bf5fdfd bug 933: Flushing ostream and files on abnormal program exit
Quincy Tse <quincy.tse@gmail.com>
parents: 3492
diff changeset
    67
 * code, but may be overridden).
0a0b6bf5fdfd bug 933: Flushing ostream and files on abnormal program exit
Quincy Tse <quincy.tse@gmail.com>
parents: 3492
diff changeset
    68
 *
0a0b6bf5fdfd bug 933: Flushing ostream and files on abnormal program exit
Quincy Tse <quincy.tse@gmail.com>
parents: 3492
diff changeset
    69
 * This macro is enabled unconditionally in all builds,
0a0b6bf5fdfd bug 933: Flushing ostream and files on abnormal program exit
Quincy Tse <quincy.tse@gmail.com>
parents: 3492
diff changeset
    70
 * including debug and optimized builds.
278
fc1133fee95d add fatal-error.h header
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    71
 */
6370
0a0b6bf5fdfd bug 933: Flushing ostream and files on abnormal program exit
Quincy Tse <quincy.tse@gmail.com>
parents: 3492
diff changeset
    72
#define NS_FATAL_ERROR(msg)                             \
324
7571b28edc22 make trailing ';' mandatory for NS_ASSERT* and NS_FATAL_ERROR macros. fix uses.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 278
diff changeset
    73
  do                                                    \
7571b28edc22 make trailing ';' mandatory for NS_ASSERT* and NS_FATAL_ERROR macros. fix uses.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 278
diff changeset
    74
    {                                                   \
6370
0a0b6bf5fdfd bug 933: Flushing ostream and files on abnormal program exit
Quincy Tse <quincy.tse@gmail.com>
parents: 3492
diff changeset
    75
      std::cerr << "msg=\"" << msg << "\", ";           \
0a0b6bf5fdfd bug 933: Flushing ostream and files on abnormal program exit
Quincy Tse <quincy.tse@gmail.com>
parents: 3492
diff changeset
    76
      NS_FATAL_ERROR_NO_MSG();                          \
324
7571b28edc22 make trailing ';' mandatory for NS_ASSERT* and NS_FATAL_ERROR macros. fix uses.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 278
diff changeset
    77
    }                                                   \
7571b28edc22 make trailing ';' mandatory for NS_ASSERT* and NS_FATAL_ERROR macros. fix uses.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 278
diff changeset
    78
  while (false)
278
fc1133fee95d add fatal-error.h header
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    79
fc1133fee95d add fatal-error.h header
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    80
#endif /* FATAL_ERROR_H */