Visual Servoing Platform  version 3.0.1
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
vpException.cpp
1 /****************************************************************************
2  *
3  * This file is part of the ViSP software.
4  * Copyright (C) 2005 - 2017 by Inria. All rights reserved.
5  *
6  * This software is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * ("GPL") version 2 as published by the Free Software Foundation.
9  * See the file LICENSE.txt at the root directory of this source
10  * distribution for additional information about the GNU GPL.
11  *
12  * For using ViSP with software that can not be combined with the GNU
13  * GPL, please contact Inria about acquiring a ViSP Professional
14  * Edition License.
15  *
16  * See http://visp.inria.fr for more information.
17  *
18  * This software was developed at:
19  * Inria Rennes - Bretagne Atlantique
20  * Campus Universitaire de Beaulieu
21  * 35042 Rennes Cedex
22  * France
23  *
24  * If you have questions regarding the use of this file, please contact
25  * Inria at visp@inria.fr
26  *
27  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
28  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
29  *
30  * Description:
31  * Exception handling.
32  *
33  * Authors:
34  * Nicolas Mansard
35  *
36  *****************************************************************************/
37 
38 
39 /* \file vpException.cpp
40  \brief error that can be emited by the vp class and its derivates
41  */
42 
43 #include <stdio.h>
44 #include "visp3/core/vpException.h"
45 
46 
47 /* ------------------------------------------------------------------------- */
48 /* --- CONSTRUCTORS -------------------------------------------------------- */
49 /* ------------------------------------------------------------------------- */
51  : code (id), message ()
52 {
53 }
54 
55 vpException::vpException (int id, const std::string & msg)
56  : code (id), message (msg)
57 {
58 }
59 
60 vpException::vpException (int id, const char* format, ...)
61  : code (id), message ()
62 {
63  va_list args;
64  va_start(args, format);
65  setMessage(format, args);
66  va_end (args);
67 }
68 
69 vpException::vpException (const int id, const char* format, va_list args)
70  : code (id), message ()
71 {
72  setMessage(format, args);
73 }
74 /* ------------------------------------------------------------------------ */
75 /* --- DESTRUCTORS -------------------------------------------------------- */
76 /* ------------------------------------------------------------------------ */
77 
78 /* Destructeur par default suffisant. */
79 // vpException::
80 // ~vpException (void)
81 // {
82 // }
83 
84 
85 void vpException::setMessage(const char* format, va_list args)
86 {
87  char buffer[1024];
88  vsnprintf (buffer, 1024, format, args);
89  std::string msg(buffer);
90  message = msg;
91 }
92 
93 /* ------------------------------------------------------------------------ */
94 /* --- ACCESSORS ---------------------------------------------------------- */
95 /* ------------------------------------------------------------------------ */
96 
97 const char *vpException::getMessage (void) const
98 {
99  return (this->message) .c_str();
100 }
101 
102 const std::string &vpException::getStringMessage (void) const
103 {
104  return this->message;
105 }
106 
107 int
109 {
110  return this->code;
111 }
112 
119 const char* vpException::what () const throw()
120 {
121  return (this->message) .c_str();
122 }
123 
124 
125 /* ------------------------------------------------------------------------- */
126 /* --- MODIFIORS ----------------------------------------------------------- */
127 /* ------------------------------------------------------------------------- */
128 
129 /* ------------------------------------------------------------------------- */
130 /* --- OP << --------------------------------------------------------------- */
131 /* ------------------------------------------------------------------------- */
132 
133 VISP_EXPORT std::ostream &
134 operator << (std::ostream & os, const vpException & error)
135 {
136  os << "Error [" << error.code << "]:\t" << error.message << std::endl;
137 
138  return os;
139 }
140 
141 
142 /*
143  * Local variables:
144  * c-basic-offset: 2
145  * End:
146  */
int getCode(void)
Send the object code.
error that can be emited by ViSP classes.
Definition: vpException.h:73
const char * what() const
void setMessage(const char *format, va_list args)
Set the message container.
Definition: vpException.cpp:85
std::string message
Contains an error message (can be empty)
Definition: vpException.h:81
int code
Contains the error code, see the errorCodeEnum table for details.
Definition: vpException.h:78
const char * getMessage(void) const
Definition: vpException.cpp:97
friend std::ostream & operator<<(std::ostream &s, const vpArray2D< Type > &A)
Definition: vpArray2D.h:267
vpException()
forbid the empty constructor (protected)
Definition: vpException.h:87
const std::string & getStringMessage(void) const
Send a reference (constant) related the error message (can be empty).