1 /*
2   Copyright (c) 2017, 2021, Oracle and/or its affiliates.
3 
4   This program is free software; you can redistribute it and/or modify
5   it under the terms of the GNU General Public License, version 2.0,
6   as published by the Free Software Foundation.
7 
8   This program is also distributed with certain software (including
9   but not limited to OpenSSL) that is licensed under separate terms,
10   as designated in a particular file or component or in included license
11   documentation.  The authors of MySQL hereby grant you an additional
12   permission to link the program and your derivative works with the
13   separately licensed software that they have included with MySQL.
14 
15   This program is distributed in the hope that it will be useful,
16   but WITHOUT ANY WARRANTY; without even the implied warranty of
17   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18   GNU General Public License, version 2.0, for more details.
19 
20   You should have received a copy of the GNU General Public License
21   along with this program; if not, write to the Free Software Foundation,
22   51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA
23 */
24 
25 /**
26   @file
27 
28   @brief
29   This file defines functions to convert exceptions to MySQL error messages.
30 */
31 
32 #include "sql_exception_handler.h"
33 
34 #include <new> // std::bad_alloc
35 #include <stdexcept> // Other std exceptions
36 
37 #include "my_global.h"  // MYF
38 #include "my_sys.h"       // my_error
39 #include "mysqld_error.h" // Error codes
40 
handle_std_exception(const char * funcname)41 void handle_std_exception(const char *funcname)
42 {
43   try
44   {
45     throw;
46   }
47   catch (const std::bad_alloc &e)
48   {
49     my_error(ER_STD_BAD_ALLOC_ERROR, MYF(0), e.what(), funcname);
50   }
51   catch (const std::domain_error &e)
52   {
53     my_error(ER_STD_DOMAIN_ERROR, MYF(0), e.what(), funcname);
54   }
55   catch (const std::length_error &e)
56   {
57     my_error(ER_STD_LENGTH_ERROR, MYF(0), e.what(), funcname);
58   }
59   catch (const std::invalid_argument &e)
60   {
61     my_error(ER_STD_INVALID_ARGUMENT, MYF(0), e.what(), funcname);
62   }
63   catch (const std::out_of_range &e)
64   {
65     my_error(ER_STD_OUT_OF_RANGE_ERROR, MYF(0), e.what(), funcname);
66   }
67   catch (const std::overflow_error &e)
68   {
69     my_error(ER_STD_OVERFLOW_ERROR, MYF(0), e.what(), funcname);
70   }
71   catch (const std::range_error &e)
72   {
73     my_error(ER_STD_RANGE_ERROR, MYF(0), e.what(), funcname);
74   }
75   catch (const std::underflow_error &e)
76   {
77     my_error(ER_STD_UNDERFLOW_ERROR, MYF(0), e.what(), funcname);
78   }
79   catch (const std::logic_error &e)
80   {
81     my_error(ER_STD_LOGIC_ERROR, MYF(0), e.what(), funcname);
82   }
83   catch (const std::runtime_error &e)
84   {
85     my_error(ER_STD_RUNTIME_ERROR, MYF(0), e.what(), funcname);
86   }
87   catch (const std::exception &e)
88   {
89     my_error(ER_STD_UNKNOWN_EXCEPTION, MYF(0), e.what(), funcname);
90   }
91   catch (...)
92   {
93     my_error(ER_UNKNOWN_ERROR, MYF(0));
94   }
95 }
96 
97