File: Error.h

package info (click to toggle)
subcommander 2.0.0~b5p1-2
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 14,880 kB
  • ctags: 9,003
  • sloc: cpp: 63,591; sh: 3,904; xml: 1,984; makefile: 1,166; ansic: 786; ruby: 251; lisp: 24
file content (96 lines) | stat: -rw-r--r-- 1,857 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/* ====================================================================
 * Copyright (c) 2003-2006, 2008  Martin Hauner
 *                                http://subcommander.tigris.org
 *
 * Subcommander is licensed as described in the file doc/COPYING, which
 * you should have received as part of this distribution.
 * ====================================================================
 */

#ifndef _SC_UTIL_ERROR_H
#define _SC_UTIL_ERROR_H

// sc
#include "String.h"

// boost
#include <boost/shared_ptr.hpp>


namespace sc
{

/**
 * general error interface.
 */
class Error
{
public:
  virtual ~Error() {}

  /**
   * \return the error code.
   */
  virtual long getCode() const = 0;

  /**
   * \return the error message of \b only this error. It does ignore
   * the nested error.
   */
  virtual sc::String getMessage() const = 0;

  /**
   * \return the error message of this error and of the nested error.
   */
  virtual sc::String getMessages() const = 0;

  /**
   * \return a nested Error or 0 if the there is none.
   */
  virtual const Error* getNested() const = 0;
};

/**
 * the success error.
 */
class Error;
extern Error* Success;

/**
 * create a new Error.
 * \param code the error code.
 * \param msg  the error msg.
 * \return a new Error.
 */
const Error* createError( long code, const sc::String& msg );

/**
 * create a new Error with a nested Error.
 * \param code the error code.
 * \param msg  the error msg.
 * \param err  the nested error.
 * \return a new Error.
 */
const Error* createError( long code, const sc::String& msg, const Error* err );


/**
 * a helper macro for handling errors
 */
#define SC_ERR(exp)\
{\
  const sc::Error* sc_err = (exp);\
  if( sc_err != sc::Success )\
  {\
    return sc_err;\
  }\
}

} // namespace



typedef boost::shared_ptr<const sc::Error> ScErrorPtr;


#endif //  _SC_UTIL_ERROR_H