You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

105 lines
2.9 KiB

  1. // Copyright ?2004, 2010, Oracle and/or its affiliates. All rights reserved.
  2. //
  3. // MySQL Connector/NET is licensed under the terms of the GPLv2
  4. // <http://www.gnu.org/licenses/old-licenses/gpl-2.0.html>, like most
  5. // MySQL Connectors. There are special exceptions to the terms and
  6. // conditions of the GPLv2 as it is applied to this software, see the
  7. // FLOSS License Exception
  8. // <http://www.mysql.com/about/legal/licensing/foss-exception.html>.
  9. //
  10. // This program is free software; you can redistribute it and/or modify
  11. // it under the terms of the GNU General Public License as published
  12. // by the Free Software Foundation; version 2 of the License.
  13. //
  14. // This program is distributed in the hope that it will be useful, but
  15. // WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  16. // or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  17. // for more details.
  18. //
  19. // You should have received a copy of the GNU General Public License along
  20. // with this program; if not, write to the Free Software Foundation, Inc.,
  21. // 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  22. #if NET40 || NET461
  23. using System;
  24. using System.Data.Common;
  25. using System.Runtime.Serialization;
  26. namespace Externals.MySql.Data.MySqlClient
  27. {
  28. /// <summary>
  29. /// The exception that is thrown when MySQL returns an error. This class cannot be inherited.
  30. /// </summary>
  31. /// <include file='Externals/MySql.Data-6.9.11/docs/mysqlException.xml' path='MyDocs/MyMembers[@name="Class"]/*'/>
  32. [Serializable]
  33. internal sealed class MySqlException : DbException
  34. {
  35. private int errorCode;
  36. private bool isFatal;
  37. internal MySqlException()
  38. {
  39. }
  40. internal MySqlException(string msg)
  41. : base(msg)
  42. {
  43. }
  44. internal MySqlException(string msg, Exception ex)
  45. : base(msg, ex)
  46. {
  47. }
  48. internal MySqlException(string msg, bool isFatal, Exception inner)
  49. : base(msg, inner)
  50. {
  51. this.isFatal = isFatal;
  52. }
  53. internal MySqlException(string msg, int errno, Exception inner)
  54. : this(msg, inner)
  55. {
  56. errorCode = errno;
  57. Data.Add("Server Error Code", errno);
  58. }
  59. internal MySqlException(string msg, int errno)
  60. : this(msg, errno, null)
  61. {
  62. }
  63. private MySqlException(SerializationInfo info, StreamingContext context)
  64. : base(info, context)
  65. {
  66. }
  67. /// <summary>
  68. /// Gets a number that identifies the type of error.
  69. /// </summary>
  70. public int Number
  71. {
  72. get { return errorCode; }
  73. }
  74. /// <summary>
  75. /// True if this exception was fatal and cause the closing of the connection, false otherwise.
  76. /// </summary>
  77. internal bool IsFatal
  78. {
  79. get { return isFatal; }
  80. }
  81. internal bool IsQueryAborted
  82. {
  83. get
  84. {
  85. return (errorCode == (int)MySqlErrorCode.QueryInterrupted ||
  86. errorCode == (int)MySqlErrorCode.FileSortAborted);
  87. }
  88. }
  89. }
  90. }
  91. #endif