github.com/grumpyhome/grumpy@v0.3.1-0.20201208125205-7b775405bdf1/grumpy-runtime-src/runtime/exceptions.go (about) 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 15 package grumpy 16 17 var ( 18 // ArithmeticErrorType corresponds to the Python type 'ArithmeticError'. 19 ArithmeticErrorType = newSimpleType("ArithmeticError", StandardErrorType) 20 // AssertionErrorType corresponds to the Python type 'AssertionError'. 21 AssertionErrorType = newSimpleType("AssertionError", StandardErrorType) 22 // AttributeErrorType corresponds to the Python type 'AttributeError'. 23 AttributeErrorType = newSimpleType("AttributeError", StandardErrorType) 24 // BytesWarningType corresponds to the Python type 'BytesWarning'. 25 BytesWarningType = newSimpleType("BytesWarning", WarningType) 26 // DeprecationWarningType corresponds to the Python type 'DeprecationWarning'. 27 DeprecationWarningType = newSimpleType("DeprecationWarning", WarningType) 28 // EnvironmentErrorType corresponds to the Python type 29 // 'EnvironmentError'. 30 EnvironmentErrorType = newSimpleType("EnvironmentError", StandardErrorType) 31 // EOFErrorType corresponds to the Python type 'EOFError'. 32 EOFErrorType = newSimpleType("EOFError", StandardErrorType) 33 // ExceptionType corresponds to the Python type 'Exception'. 34 ExceptionType = newSimpleType("Exception", BaseExceptionType) 35 // FutureWarningType corresponds to the Python type 'FutureWarning'. 36 FutureWarningType = newSimpleType("FutureWarning", WarningType) 37 // ImportErrorType corresponds to the Python type 'ImportError'. 38 ImportErrorType = newSimpleType("ImportError", StandardErrorType) 39 // ImportWarningType corresponds to the Python type 'ImportWarning'. 40 ImportWarningType = newSimpleType("ImportWarning", WarningType) 41 // IndexErrorType corresponds to the Python type 'IndexError'. 42 IndexErrorType = newSimpleType("IndexError", LookupErrorType) 43 // IOErrorType corresponds to the Python type 'IOError'. 44 IOErrorType = newSimpleType("IOError", EnvironmentErrorType) 45 // KeyboardInterruptType corresponds to the Python type 'KeyboardInterrupt'. 46 KeyboardInterruptType = newSimpleType("KeyboardInterrupt", BaseExceptionType) 47 // KeyErrorType corresponds to the Python type 'KeyError'. 48 KeyErrorType = newSimpleType("KeyError", LookupErrorType) 49 // LookupErrorType corresponds to the Python type 'LookupError'. 50 LookupErrorType = newSimpleType("LookupError", StandardErrorType) 51 // MemoryErrorType corresponds to the Python type 'MemoryError'. 52 MemoryErrorType = newSimpleType("MemoryError", StandardErrorType) 53 // NameErrorType corresponds to the Python type 'NameError'. 54 NameErrorType = newSimpleType("NameError", StandardErrorType) 55 // NotImplementedErrorType corresponds to the Python type 56 // 'NotImplementedError'. 57 NotImplementedErrorType = newSimpleType("NotImplementedError", RuntimeErrorType) 58 // OSErrorType corresponds to the Python type 'OSError'. 59 OSErrorType = newSimpleType("OSError", EnvironmentErrorType) 60 // OverflowErrorType corresponds to the Python type 'OverflowError'. 61 OverflowErrorType = newSimpleType("OverflowError", ArithmeticErrorType) 62 // PendingDeprecationWarningType corresponds to the Python type 'PendingDeprecationWarning'. 63 PendingDeprecationWarningType = newSimpleType("PendingDeprecationWarning", WarningType) 64 // ReferenceErrorType corresponds to the Python type 'ReferenceError'. 65 ReferenceErrorType = newSimpleType("ReferenceError", StandardErrorType) 66 // RuntimeErrorType corresponds to the Python type 'RuntimeError'. 67 RuntimeErrorType = newSimpleType("RuntimeError", StandardErrorType) 68 // RuntimeWarningType corresponds to the Python type 'RuntimeWarning'. 69 RuntimeWarningType = newSimpleType("RuntimeWarning", WarningType) 70 // StandardErrorType corresponds to the Python type 'StandardError'. 71 StandardErrorType = newSimpleType("StandardError", ExceptionType) 72 // StopIterationType corresponds to the Python type 'StopIteration'. 73 StopIterationType = newSimpleType("StopIteration", ExceptionType) 74 // SyntaxErrorType corresponds to the Python type 'SyntaxError'. 75 SyntaxErrorType = newSimpleType("SyntaxError", StandardErrorType) 76 // SyntaxWarningType corresponds to the Python type 'SyntaxWarning'. 77 SyntaxWarningType = newSimpleType("SyntaxWarning", WarningType) 78 // SystemErrorType corresponds to the Python type 'SystemError'. 79 SystemErrorType = newSimpleType("SystemError", StandardErrorType) 80 // SystemExitType corresponds to the Python type 'SystemExit'. 81 SystemExitType = newSimpleType("SystemExit", BaseExceptionType) 82 // TypeErrorType corresponds to the Python type 'TypeError'. 83 TypeErrorType = newSimpleType("TypeError", StandardErrorType) 84 // UnboundLocalErrorType corresponds to the Python type 85 // 'UnboundLocalError'. 86 UnboundLocalErrorType = newSimpleType("UnboundLocalError", NameErrorType) 87 // UnicodeDecodeErrorType corresponds to the Python type 'UnicodeDecodeError'. 88 UnicodeDecodeErrorType = newSimpleType("UnicodeDecodeError", ValueErrorType) 89 // UnicodeEncodeErrorType corresponds to the Python type 'UnicodeEncodeError'. 90 UnicodeEncodeErrorType = newSimpleType("UnicodeEncodeError", ValueErrorType) 91 // UnicodeErrorType corresponds to the Python type 'UnicodeError'. 92 UnicodeErrorType = newSimpleType("UnicodeError", ValueErrorType) 93 // UnicodeWarningType corresponds to the Python type 'UnicodeWarning'. 94 UnicodeWarningType = newSimpleType("UnicodeWarning", WarningType) 95 // UserWarningType corresponds to the Python type 'UserWarning'. 96 UserWarningType = newSimpleType("UserWarning", WarningType) 97 // ValueErrorType corresponds to the Python type 'ValueError'. 98 ValueErrorType = newSimpleType("ValueError", StandardErrorType) 99 // WarningType corresponds to the Python type 'Warning'. 100 WarningType = newSimpleType("Warning", ExceptionType) 101 // ZeroDivisionErrorType corresponds to the Python type 102 // 'ZeroDivisionError'. 103 ZeroDivisionErrorType = newSimpleType("ZeroDivisionError", ArithmeticErrorType) 104 ) 105 106 func systemExitInit(f *Frame, o *Object, args Args, kwargs KWArgs) (*Object, *BaseException) { 107 baseExceptionInit(f, o, args, kwargs) 108 code := None 109 if len(args) > 0 { 110 code = args[0] 111 } 112 if raised := SetAttr(f, o, NewStr("code"), code); raised != nil { 113 return nil, raised 114 } 115 return None, nil 116 } 117 118 func initSystemExitType(map[string]*Object) { 119 SystemExitType.slots.Init = &initSlot{systemExitInit} 120 }