SIMLIB/C++ 3.09
Loading...
Searching...
No Matches
error.cc
Go to the documentation of this file.
1/////////////////////////////////////////////////////////////////////////////
2//! \file error.cc error messages processing
3//
4// Copyright (c) 1991-2004 Petr Peringer
5//
6// This library is licensed under GNU Library GPL. See the file COPYING.
7//
8
9// internal error messages
10
11////////////////////////////////////////////////////////////////////////////
12// interface
13//
14
15#include "simlib.h"
16#include "internal.h"
17
18#include <cstdlib>
19#include <cstdio>
20#include <cstdarg>
21
22
23////////////////////////////////////////////////////////////////////////////
24// implementation
25//
26
27namespace simlib3 {
28
30
31#define _ERR_TXT "\nERROR, Time=%g : %s \n"
32#define _INT_ERR_TXT "\nERROR, Time=%g : %s (file:%s line:%d)\n"
33#define _ABORT_TXT "\n ========== Simulation aborted ========== \n"
34#define _WARNING_TXT "\nWARNING, Time=%g : %s \n"
35
36////////////////////////////////////////////////////////////////////////////
37/// print error message and abort program
38void SIMLIB_error(const enum _ErrEnum N)
39{
40 _Print(_ERR_TXT, (double)Time, _ErrMsg(N));
43 SIMLIB_DynamicFlag = false;
44 exit(3);
45}
46
47/// print error message and abort program
48void SIMLIB_error(const char *fmt, ... )
49{
50 char s[100];
51 va_list argptr;
52 va_start(argptr, fmt);
53 vsnprintf(s, sizeof(s), fmt, argptr);
54 va_end(argptr);
55 _Print(_ERR_TXT, (double)Time, s);
57 exit(1);
58}
59
60/// print error message and abort program
61void SIMLIB_error(const char*filename, const int linenum)
62{
63 _Print(_INT_ERR_TXT, (double)Time,
65 filename, linenum);
68 SIMLIB_DynamicFlag = false; // if in continuous simulation algorithm
69 exit(3);
70}
71
72////////////////////////////////////////////////////////////////////////////
73/// print warning message and continue
74void SIMLIB_warning( const enum _ErrEnum N )
75{
76 _Print(_WARNING_TXT, (double)Time, _ErrMsg(N));
77}
78
79/// print warning message and continue
80void SIMLIB_warning(const char *fmt, ... )
81{
82 char s[100];
83 va_list argptr;
84 va_start(argptr, fmt);
85 vsnprintf(s, sizeof(s), fmt, argptr);
86 _Print(_ERR_TXT, (double)Time, s);
87 va_end(argptr);
88}
89
90} // namespace
91
#define _WARNING_TXT
Definition: error.cc:34
#define _ABORT_TXT
Definition: error.cc:33
#define _INT_ERR_TXT
Definition: error.cc:32
#define _ERR_TXT
Definition: error.cc:31
_ErrEnum
Definition: errors.h:9
@ InternalError
Definition: errors.h:12
Internal header file for SIMLIB/C++.
Implementation of class CalendarList interface is static - using global functions in SQS namespace.
Definition: algloop.cc:32
const double & Time
model time (is NOT the block)
Definition: run.cc:48
bool SIMLIB_DynamicFlag
in dynamic section
Definition: intg.cc:56
void SIMLIB_error(const enum _ErrEnum N)
print error message and abort program
Definition: error.cc:38
@ ERROREXIT
Definition: internal.h:81
SIMLIB_IMPLEMENTATION
Definition: algloop.cc:34
int _Print(const char *fmt,...)
output of messages to stdout, too
Definition: print.cc:68
void SIMLIB_warning(const enum _ErrEnum N)
print warning message and continue
Definition: error.cc:74
SIMLIB_Phase_t SIMLIB_Phase
Definition: run.cc:57
const char * _ErrMsg(enum _ErrEnum N)
Definition: errors.cc:97
Main SIMLIB/C++ interface.