5 * Created by Alyssa Milburn on Sat 13 Nov 2004.
6 * Copyright (c) 2004-2005 Alyssa Milburn. All rights reserved.
7 * Copyright (c) 2005-2006 Bryan Donlan. All rights reserved.
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
20 #ifndef __C2EEXCEPTIONS_H
21 #define __C2EEXCEPTIONS_H
29 #include <boost/shared_ptr.hpp>
30 #include <boost/scoped_ptr.hpp>
34 class creaturesException
: public std::exception
{
41 virtual std::string
prettyPrint() const { return std::string(what()); }
42 creaturesException(const creaturesException
&e
) throw() : std::exception() {
43 // catch clause missing & etc, we'll try to patch over it but you should fix it really.
44 fprintf(stderr
, "QA: creaturesException copy constructor called.\n");
48 creaturesException(const char *s
) throw() { r
= s
; malloced
= false; }
49 creaturesException(const std::string
&s
) throw() {
50 r
= strdup(s
.c_str());
56 ~creaturesException() throw() {
57 if (malloced
) free((void *)r
);
59 const char* what() const throw() { return r
; }
62 class caosException
: public creaturesException
{
64 boost::shared_ptr
<class script
> script
;
68 /* debug hook, removeme */
69 virtual const char *what() const throw() { return this->creaturesException::what(); }
71 ~caosException() throw() { }
73 caosException(const std::string
&d
) throw() : creaturesException(d
), traceindex(-1) { }
75 caosException(const char *d
) throw() : creaturesException(d
), traceindex(-1) { }
77 void trace(boost::shared_ptr
<class script
> scr
, int traceindex
= -1) throw();
79 virtual std::string
prettyPrint() const;
84 static inline std::string
buildExceptionString(const char *s
, const char *file
, int line
) {
85 std::ostringstream oss
;
86 oss
<< s
<< " at " << file
<< ':' << line
;
91 struct tracedAssertFailure
: public creaturesException
{
92 tracedAssertFailure(const char *s
, const char *file
, int line
)
93 : creaturesException(buildExceptionString(s
, file
, line
)) { }
97 class tokeniseFailure
: public creaturesException
{
99 tokeniseFailure(const char *s
) throw() : creaturesException(s
) { }
100 tokeniseFailure(const std::string
&s
) throw() : creaturesException(s
) { }
103 class parseFailure
: public creaturesException
{
105 parseFailure(const char *s
) throw()
106 : creaturesException(s
), lineno(-1) { }
107 parseFailure(const std::string
&s
) throw()
108 : creaturesException(s
), lineno(-1) { }
109 ~parseFailure() throw() { }
111 boost::shared_ptr
<std::vector
<class token
> > context
;
113 std::string filename
;
116 std::string
prettyPrint() const;
119 typedef parseFailure parseException
;
121 class genomeException
: public creaturesException
{
123 genomeException(const char *s
) throw() : creaturesException(s
) { }
124 genomeException(const std::string
&s
) throw() : creaturesException(s
) { }