File: AiksaurusException.cpp

package info (click to toggle)
aiksaurus 1.2.1%2Bdev-0.12-7.2
  • links: PTS
  • area: main
  • in suites: forky, sid, trixie
  • size: 99,564 kB
  • sloc: cpp: 9,872; sh: 8,411; objc: 466; php: 375; makefile: 214
file content (161 lines) | stat: -rw-r--r-- 5,898 bytes parent folder | download | duplicates (8)
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
/*
 * Aiksaurus - An English-language thesaurus library
 * Copyright (C) 2001-2002 by Jared Davis
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  
 * 02111-1307, USA.
 *
 */

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include "AiksaurusException.h"     // Header we're implementing.

#include <cassert>                   
#include <string>                   // for std::string
#include <cstring>                  // for strcpy
#include <new>                      // for std::bad_alloc

using namespace std;

#if defined WIN32
	extern std::string AIK_DATA_DIR;
#endif

namespace AiksaurusImpl
{
    const char* AiksaurusException::MemoryError = 
        "Error: Cannot Allocate Memory\n"
        "No memory was available for the Thesaurus.  You  \n"
        "could try closing some other programs to make more \n"
        "memory available.\n";

   
    AiksaurusException::AiksaurusException(const AiksaurusException& rhs) throw()
    {
        try {
            d_description = rhs.getDescription();
        }
        catch(std::bad_alloc)
        {
            d_description = MemoryError;
        }
    }
        
    
    AiksaurusException::AiksaurusException(Code code) throw()
    {
        assert(
            (code == CANNOT_OPEN_MEANINGS_FILE) ||
            (code == CORRUPT_MEANINGS_FILE) ||
            (code == CANNOT_OPEN_WORDS_FILE) ||
            (code == CORRUPT_WORDS_FILE) ||
            (code == CANNOT_ALLOCATE_MEMORY)
        );

        if (code == CANNOT_ALLOCATE_MEMORY)
        {
            return;
        }
        
        try 
        {    
            switch(code)
            {
                case CANNOT_OPEN_MEANINGS_FILE:
                    d_description = "Error: Cannot Open Meanings File\n"
                          "There has been a problem opening the file:\n   ";
                    d_description += AIK_DATA_DIR;
                    d_description += "meanings.dat\n\n"
                           "This most likely indicates that the file has been \n"
                           "moved or deleted.  If you cannot find the file, you \n"
                           "can download a new copy from: \n"
                           "   http://www.aiksaurus.com/_support/015/meanings.dat\n";
                    break;

                    
                case CORRUPT_MEANINGS_FILE:
                    d_description = "Error: Corrupt Meanings File\n"
                          "There has been a problem reading the file:\n   ";
                    d_description += AIK_DATA_DIR;
                    d_description += "meanings.dat\n\n"
                           "The file exists, but was not read correctly.  Either \n"
                           "the file has become corrupt or this is a bug. \n\n"
                           "Please download a new copy of the file from: \n"
                           "   http://www.aiksaurus.com/_support/015/meanings.dat\n\n"
                           "If this does not fix the problem, please contact \n"
                           "   jared@aiksaurus.com\n";
                    break;
        
                    
                case CANNOT_OPEN_WORDS_FILE:
                    d_description = "Error: Cannot Open Words File\n"
                          "There has been a problem opening the file:\n   ";
                    d_description += AIK_DATA_DIR;
                    d_description += "words.dat\n\n"
                           "This most likely indicates that the file has been \n"
                           "moved or deleted.  If you cannot find the file, you \n"
                           "can download a new copy from: \n"
                           "   http://www.aiksaurus.com/_support/015/words.dat\n";
                    break;
    
                    
                case CORRUPT_WORDS_FILE: 
                    d_description = "Error: Corrupt Words File\n"
                          "There has been a problem reading the file:\n   ";
                    d_description += AIK_DATA_DIR;
                    d_description += "words.dat\n\n"        
                           "The file exists, but was not read correctly.  Either \n"
                           "the file has become corrupt or this is a bug. \n\n"
                           "Please download a new copy of the file from: \n"
                           "   http://www.aiksaurus.com/_support/015/words.dat\n\n"
                           "If this does not fix the problem, please contact \n"
                           "   jared@aiksaurus.com\n";
                    break;

                default: 
                    // shut up the compiler about not handling CANNOT_ALLOCATE_MEMORY
                    // in the switch statement.  We handled it before.
                    break;
                    
            }
        }
        
        catch(std::bad_alloc)
        {
            d_description = "";
        }
    }

    
    AiksaurusException::~AiksaurusException() throw()
    {
    }


    const char* 
    AiksaurusException::getDescription() const throw()
    {
        try {
            return (d_description != "") ? d_description.c_str() : MemoryError;
        }
        catch(std::bad_alloc) {
            return MemoryError;
        }
    }
}