/runtime/exceptions.go

https://github.com/google/grumpy · Go · 120 lines · 58 code · 4 blank · 58 comment · 3 complexity · ac58d8083fe29a0c3dcbac02e076dcdf MD5 · raw file

  1. // Copyright 2016 Google Inc. All Rights Reserved.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package grumpy
  15. var (
  16. // ArithmeticErrorType corresponds to the Python type 'ArithmeticError'.
  17. ArithmeticErrorType = newSimpleType("ArithmeticError", StandardErrorType)
  18. // AssertionErrorType corresponds to the Python type 'AssertionError'.
  19. AssertionErrorType = newSimpleType("AssertionError", StandardErrorType)
  20. // AttributeErrorType corresponds to the Python type 'AttributeError'.
  21. AttributeErrorType = newSimpleType("AttributeError", StandardErrorType)
  22. // BytesWarningType corresponds to the Python type 'BytesWarning'.
  23. BytesWarningType = newSimpleType("BytesWarning", WarningType)
  24. // DeprecationWarningType corresponds to the Python type 'DeprecationWarning'.
  25. DeprecationWarningType = newSimpleType("DeprecationWarning", WarningType)
  26. // EnvironmentErrorType corresponds to the Python type
  27. // 'EnvironmentError'.
  28. EnvironmentErrorType = newSimpleType("EnvironmentError", StandardErrorType)
  29. // EOFErrorType corresponds to the Python type 'EOFError'.
  30. EOFErrorType = newSimpleType("EOFError", StandardErrorType)
  31. // ExceptionType corresponds to the Python type 'Exception'.
  32. ExceptionType = newSimpleType("Exception", BaseExceptionType)
  33. // FutureWarningType corresponds to the Python type 'FutureWarning'.
  34. FutureWarningType = newSimpleType("FutureWarning", WarningType)
  35. // ImportErrorType corresponds to the Python type 'ImportError'.
  36. ImportErrorType = newSimpleType("ImportError", StandardErrorType)
  37. // ImportWarningType corresponds to the Python type 'ImportWarning'.
  38. ImportWarningType = newSimpleType("ImportWarning", WarningType)
  39. // IndexErrorType corresponds to the Python type 'IndexError'.
  40. IndexErrorType = newSimpleType("IndexError", LookupErrorType)
  41. // IOErrorType corresponds to the Python type 'IOError'.
  42. IOErrorType = newSimpleType("IOError", EnvironmentErrorType)
  43. // KeyboardInterruptType corresponds to the Python type 'KeyboardInterrupt'.
  44. KeyboardInterruptType = newSimpleType("KeyboardInterrupt", BaseExceptionType)
  45. // KeyErrorType corresponds to the Python type 'KeyError'.
  46. KeyErrorType = newSimpleType("KeyError", LookupErrorType)
  47. // LookupErrorType corresponds to the Python type 'LookupError'.
  48. LookupErrorType = newSimpleType("LookupError", StandardErrorType)
  49. // MemoryErrorType corresponds to the Python type 'MemoryError'.
  50. MemoryErrorType = newSimpleType("MemoryError", StandardErrorType)
  51. // NameErrorType corresponds to the Python type 'NameError'.
  52. NameErrorType = newSimpleType("NameError", StandardErrorType)
  53. // NotImplementedErrorType corresponds to the Python type
  54. // 'NotImplementedError'.
  55. NotImplementedErrorType = newSimpleType("NotImplementedError", RuntimeErrorType)
  56. // OSErrorType corresponds to the Python type 'OSError'.
  57. OSErrorType = newSimpleType("OSError", EnvironmentErrorType)
  58. // OverflowErrorType corresponds to the Python type 'OverflowError'.
  59. OverflowErrorType = newSimpleType("OverflowError", ArithmeticErrorType)
  60. // PendingDeprecationWarningType corresponds to the Python type 'PendingDeprecationWarning'.
  61. PendingDeprecationWarningType = newSimpleType("PendingDeprecationWarning", WarningType)
  62. // ReferenceErrorType corresponds to the Python type 'ReferenceError'.
  63. ReferenceErrorType = newSimpleType("ReferenceError", StandardErrorType)
  64. // RuntimeErrorType corresponds to the Python type 'RuntimeError'.
  65. RuntimeErrorType = newSimpleType("RuntimeError", StandardErrorType)
  66. // RuntimeWarningType corresponds to the Python type 'RuntimeWarning'.
  67. RuntimeWarningType = newSimpleType("RuntimeWarning", WarningType)
  68. // StandardErrorType corresponds to the Python type 'StandardError'.
  69. StandardErrorType = newSimpleType("StandardError", ExceptionType)
  70. // StopIterationType corresponds to the Python type 'StopIteration'.
  71. StopIterationType = newSimpleType("StopIteration", ExceptionType)
  72. // SyntaxErrorType corresponds to the Python type 'SyntaxError'.
  73. SyntaxErrorType = newSimpleType("SyntaxError", StandardErrorType)
  74. // SyntaxWarningType corresponds to the Python type 'SyntaxWarning'.
  75. SyntaxWarningType = newSimpleType("SyntaxWarning", WarningType)
  76. // SystemErrorType corresponds to the Python type 'SystemError'.
  77. SystemErrorType = newSimpleType("SystemError", StandardErrorType)
  78. // SystemExitType corresponds to the Python type 'SystemExit'.
  79. SystemExitType = newSimpleType("SystemExit", BaseExceptionType)
  80. // TypeErrorType corresponds to the Python type 'TypeError'.
  81. TypeErrorType = newSimpleType("TypeError", StandardErrorType)
  82. // UnboundLocalErrorType corresponds to the Python type
  83. // 'UnboundLocalError'.
  84. UnboundLocalErrorType = newSimpleType("UnboundLocalError", NameErrorType)
  85. // UnicodeDecodeErrorType corresponds to the Python type 'UnicodeDecodeError'.
  86. UnicodeDecodeErrorType = newSimpleType("UnicodeDecodeError", ValueErrorType)
  87. // UnicodeEncodeErrorType corresponds to the Python type 'UnicodeEncodeError'.
  88. UnicodeEncodeErrorType = newSimpleType("UnicodeEncodeError", ValueErrorType)
  89. // UnicodeErrorType corresponds to the Python type 'UnicodeError'.
  90. UnicodeErrorType = newSimpleType("UnicodeError", ValueErrorType)
  91. // UnicodeWarningType corresponds to the Python type 'UnicodeWarning'.
  92. UnicodeWarningType = newSimpleType("UnicodeWarning", WarningType)
  93. // UserWarningType corresponds to the Python type 'UserWarning'.
  94. UserWarningType = newSimpleType("UserWarning", WarningType)
  95. // ValueErrorType corresponds to the Python type 'ValueError'.
  96. ValueErrorType = newSimpleType("ValueError", StandardErrorType)
  97. // WarningType corresponds to the Python type 'Warning'.
  98. WarningType = newSimpleType("Warning", ExceptionType)
  99. // ZeroDivisionErrorType corresponds to the Python type
  100. // 'ZeroDivisionError'.
  101. ZeroDivisionErrorType = newSimpleType("ZeroDivisionError", ArithmeticErrorType)
  102. )
  103. func systemExitInit(f *Frame, o *Object, args Args, kwargs KWArgs) (*Object, *BaseException) {
  104. baseExceptionInit(f, o, args, kwargs)
  105. code := None
  106. if len(args) > 0 {
  107. code = args[0]
  108. }
  109. if raised := SetAttr(f, o, NewStr("code"), code); raised != nil {
  110. return nil, raised
  111. }
  112. return None, nil
  113. }
  114. func initSystemExitType(map[string]*Object) {
  115. SystemExitType.slots.Init = &initSlot{systemExitInit}
  116. }