PEBL 2.2
Psychology Experiment Building Language - Cross-platform psychological experiment development system
PError.h
Go to the documentation of this file.
1//* -*- mode:C++; tab-width:4; c-basic-offset:4; indent-tabs-mode:nil -*- */
3// Name: src/utility/PError.h
4// Purpose: Utility class for signaling warnings and errors
5// Author: Shane T. Mueller, Ph.D.
6// Copyright: (c) 2003-2026 Shane T. Mueller <smueller@obereed.net>
7//
8// License: GPL 2
9//
10//
11//
12// This file is part of the PEBL project.
13//
14// PEBL is free software; you can redistribute it and/or modify
15// it under the terms of the GNU General Public License as published by
16// the Free Software Foundation; either version 2 of the License, or
17// (at your option) any later version.
18//
19// PEBL is distributed in the hope that it will be useful,
20// but WITHOUT ANY WARRANTY; without even the implied warranty of
21// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22// GNU General Public License for more details.
23//
24// You should have received a copy of the GNU General Public License
25// along with PEBL; if not, write to the Free Software
26// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28#ifndef __PERROR_H__
29#define __PERROR_H__
30
31#include <string>
32#include <list>
33#include "../base/Variant.h"
34#include "../base/PNode.h"
35
37 {
38 //These are based on variant types:
39 PEAT_UNDEFINED = 0, // undefined, error
40 PEAT_STACK_SIGNAL = 1, // an enum that signals stuff to the evaluator stack, for internal use only.
41 PEAT_FUNCTION = 2, // the name of a function.
42 PEAT_FUNCTION_POINTER = 4, // A pointer to a function. Used for compiled library functions.
43 PEAT_NUMBER = 8, // any number.
44 PEAT_INTEGER = 16, // an integer
45 PEAT_FLOAT = 32, // a float
46 PEAT_STRING = 64, // a string of characters
47 PEAT_LOCALVARIABLE = 128, // a 'variable'; i.e. a char* symbolizing another piece of data.
48 PEAT_GLOBALVARIABLE = 256, // a 'variable'; i.e. a char* symbolizing another piece of data.
49 PEAT_VARIABLE = 512, // either a local or global variable
50 PEAT_COMPLEXDATA = 1024, // Any one of a number of compex data 'objects'.
51
52 //These are based on PComplexData types:
72 };
73
74
75
76namespace PError
77{
78
79 //These functions handle error detection and reporting. To use, include this file
80 //in a source file, and then call PError::Signal....(). SignalFatalError will cause the program
81 //to close immediately, printing message as an error message to stderr. SignalWarning()
82 //will only print an error message. If you use the variety with the PNode argument, the
83 //message will report information about the original code, if it is available.
84
85 // Global flag to control whether to show GUI error dialogs
86 // Set to false for command-line tools like pebl-validator
87 // Defaults to true for normal PEBL execution
88 extern bool gShowErrorDialogs;
89
90 // Global flag to control validator mode
91 // When true, SignalFatalError throws exception instead of exiting
92 // Allows validator to collect errors and continue
93 extern bool gValidatorMode;
94
95 void SignalFatalError(const std::string & message);
96
97 void SignalWarning(const std::string & message);
98
99 void AssertType(Variant v, int type, const std::string & outsidemessage );
100 std::string GetTypeName(Variant v);
101 void ExitQuietly(const std::string & message, int exitCode = 0);
102
103}
104
105
107{
108public:
111 void Push(const PNode* node){mNodes.push_back(node);};
112 void Pop(){mNodes.pop_back();};
113 int Size(){return (int)(mNodes.size());};
114 std::ostream & PrintCallStack(std::ostream & out) const
115 {
116 std::string indent = "";
117 std::list<const PNode*>::const_iterator i = mNodes.begin();
118
119 while(i != mNodes.end())
120 {
121 out << indent << "Called from function ["<< (*i)->GetFunctionName()<< "] on line ["<<(*i)->GetLineNumber() << "] of file [" << (*i)->GetFilename() << "]\n";
122 indent = indent + " ";
123 i++;
124 }
125 return out;
126 }
127
128private:
129 std::list<const PNode*> mNodes;
130};
131
132
133
134
135#endif
PErrorAssertType
Definition PError.h:37
@ PEAT_KEYBOARD
Definition PError.h:60
@ PEAT_JOYSTICK
Definition PError.h:59
@ PEAT_FUNCTION_POINTER
Definition PError.h:42
@ PEAT_VARIABLE
Definition PError.h:49
@ PEAT_STACK_SIGNAL
Definition PError.h:40
@ PEAT_COMPLEXDATA
Definition PError.h:50
@ PEAT_FONT
Definition PError.h:57
@ PEAT_NETWORKCONNECTION
Definition PError.h:62
@ PEAT_FUNCTION
Definition PError.h:41
@ PEAT_COMPORT
Definition PError.h:65
@ PEAT_TEXTOBJECT
Definition PError.h:66
@ PEAT_LABEL
Definition PError.h:68
@ PEAT_GLOBALVARIABLE
Definition PError.h:48
@ PEAT_COLOR
Definition PError.h:54
@ PEAT_LIST
Definition PError.h:61
@ PEAT_PARALLELPORT
Definition PError.h:64
@ PEAT_TEXTBOX
Definition PError.h:67
@ PEAT_UNDEFINED
Definition PError.h:39
@ PEAT_INTEGER
Definition PError.h:44
@ PEAT_WIDGET
Definition PError.h:69
@ PEAT_WINDOW
Definition PError.h:70
@ PEAT_STRING
Definition PError.h:46
@ PEAT_OBJECT
Definition PError.h:63
@ PEAT_FLOAT
Definition PError.h:45
@ PEAT_FILESTREAM
Definition PError.h:56
@ PEAT_ENVIRONMENT
Definition PError.h:55
@ PEAT_AUDIOOUT
Definition PError.h:53
@ PEAT_IMAGEBOX
Definition PError.h:58
@ PEAT_LOCALVARIABLE
Definition PError.h:47
@ PEAT_NUMBER
Definition PError.h:43
@ PEAT_MOVIE
Definition PError.h:71
int Size()
Definition PError.h:113
void Push(const PNode *node)
Definition PError.h:111
void Pop()
Definition PError.h:112
~PCallStack()
Definition PError.h:110
PCallStack()
Definition PError.h:109
std::ostream & PrintCallStack(std::ostream &out) const
Definition PError.h:114
Definition PNode.h:45
void ExitQuietly(const std::string &message, int exitCode=0)
Definition PError.cpp:126
void SignalWarning(const std::string &message)
Definition PError.cpp:119
std::string GetTypeName(Variant v)
Definition PError.cpp:547
void AssertType(Variant v, int type, const std::string &outsidemessage)
bool gValidatorMode
Definition PError.cpp:59
void SignalFatalError(const std::string &message)
bool gShowErrorDialogs
Definition PError.cpp:56