~drizzle-trunk/drizzle/development

851 by Brian Aker
Class rewrite of Session (aka get all of the junk out)
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
 *
4
 *  Copyright (C) 2008 Sun Microsystems
5
 *
6
 *  This program is free software; you can redistribute it and/or modify
7
 *  it under the terms of the GNU General Public License as published by
8
 *  the Free Software Foundation; version 2 of the License.
9
 *
10
 *  This program is distributed in the hope that it will be useful,
11
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 *  GNU General Public License for more details.
14
 *
15
 *  You should have received a copy of the GNU General Public License
16
 *  along with this program; if not, write to the Free Software
17
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18
 */
19
20
21
#ifndef DRIZZLED_INTERNAL_ERROR_HANDLER_H
22
#define DRIZZLED_INTERNAL_ERROR_HANDLER_H
23
24
25
26
/**
27
  This class represents the interface for internal error handlers.
28
  Internal error handlers are exception handlers used by the server
29
  implementation.
30
*/
31
class Internal_error_handler
32
{
33
protected:
34
  Internal_error_handler() {}
35
  virtual ~Internal_error_handler() {}
36
37
public:
38
  /**
39
    Handle an error condition.
40
    This method can be implemented by a subclass to achieve any of the
41
    following:
42
    - mask an error internally, prevent exposing it to the user,
43
    - mask an error and throw another one instead.
44
    When this method returns true, the error condition is considered
45
    'handled', and will not be propagated to upper layers.
46
    It is the responsability of the code installing an internal handler
47
    to then check for trapped conditions, and implement logic to recover
48
    from the anticipated conditions trapped during runtime.
49
50
    This mechanism is similar to C++ try/throw/catch:
51
    - 'try' correspond to <code>Session::push_internal_handler()</code>,
52
    - 'throw' correspond to <code>my_error()</code>,
53
    which invokes <code>my_message_sql()</code>,
54
    - 'catch' correspond to checking how/if an internal handler was invoked,
55
    before removing it from the exception stack with
56
    <code>Session::pop_internal_handler()</code>.
57
58
    @param sql_errno the error number
59
    @param level the error level
60
    @param session the calling thread
61
    @return true if the error is handled
62
  */
63
  virtual bool handle_error(uint32_t sql_errno,
64
                            const char *message,
65
                            DRIZZLE_ERROR::enum_warning_level level,
66
                            Session *session) = 0;
67
};
68
#endif /* DRIZZLED_INTERNAL_ERROR_HANDLER_H */