## use regex 'throw\(.*,.*,.*\)' to find in .py files: 51 results - 12 files Lib/_collections_abc.py: 159 @abstractmethod 160: def throw(self, typ, val=None, tb=None): 161 """Raise an exception in the coroutine. 245 @abstractmethod 246: async def athrow(self, typ, val=None, tb=None): 247 """Raise an exception in the asynchronous generator. 365 @abstractmethod 366: def throw(self, typ, val=None, tb=None): 367 """Raise an exception in the generator. Lib/contextlib.py: 154 try: 155: self.gen.throw(typ, value, traceback) 156 except StopIteration as exc: 221 try: 222: await self.gen.athrow(typ, value, traceback) 223 except StopAsyncIteration as exc: Lib/types.py: 218 return self.__wrapped.send(val) 219: def throw(self, tp, *rest): 220 return self.__wrapped.throw(tp, *rest) Lib/lib2to3/fixes/fix_throw.py: 1: """Fixer for generator.throw(E, V, T). 2 4 g.throw(E, V) -> g.throw(E(V)) 5: g.throw(E, V, T) -> g.throw(E(V).with_traceback(T)) 6 7: g.throw("foo"[, V[, T]]) will warn about string exceptions.""" 8 # Author: Collin Winter Lib/test/test_asyncgen.py: 652 self.assertEqual(g.send(None), 1) 653: self.assertEqual(g.throw(MyError, MyError(), None), 2) 654 try: 665 self.assertEqual(g.send(None), 1) 666: self.assertEqual(g.throw(MyError, MyError(), None), 2) 667 with self.assertRaises(MyError): 668: g.throw(MyError, MyError(), None) 669 694 self.assertEqual(g.send(None), 10) 695: self.assertEqual(g.throw(MyError, MyError(), None), 20) 696 with self.assertRaisesRegex(MyError, 'val'): 697: g.throw(MyError, MyError('val'), None) 698 715 with self.assertRaisesRegex(StopIteration, 'default'): 716: g.throw(MyError, MyError(), None) 717 730 with self.assertRaises(MyError): 731: g.throw(MyError, MyError(), None) 732 Lib/test/test_collections.py: 807 return value 808: def throw(self, typ, val=None, tb=None): 809: super().throw(typ, val, tb) 810 def __await__(self): 857 return value 858: def throw(self, typ, val=None, tb=None): 859: super().throw(typ, val, tb) 860 def __await__(self): 885 pass 886: def throw(self, typ, val=None, tb=None): 887 pass 1173 def close(self): pass 1174: def throw(self, typ, val=None, tb=None): pass 1175 1184 def send(self, value): return value 1185: def throw(self, typ, val=None, tb=None): pass 1186 1198 def send(self, value): return value 1199: def throw(self, typ, val=None, tb=None): pass 1200 1203 return value 1204: def throw(self, typ, val=None, tb=None): 1205: super().throw(typ, val, tb) 1206 1244 def aclose(self): pass 1245: def athrow(self, typ, val=None, tb=None): pass 1246 1255 def asend(self, value): return value 1256: def athrow(self, typ, val=None, tb=None): pass 1257 1269 async def asend(self, value): return value 1270: async def athrow(self, typ, val=None, tb=None): pass 1271 1274 return value 1275: async def athrow(self, typ, val=None, tb=None): 1276: await super().athrow(typ, val, tb) 1277 Lib/test/test_coroutines.py: 711 with self.assertRaises(ZeroDivisionError): 712: aw.throw(ZeroDivisionError, None, None) 713 self.assertEqual(N, 102) Lib/test/test_generators.py: 2121 2122: >>> g.throw(ValueError, ValueError(1), None) # explicit None traceback 2123 caught ValueError (1) 2129 2130: >>> g.throw(ValueError, "foo", 23) # bad args 2131 Traceback (most recent call last): Lib/test/test_types.py: 1954 1955: wrapper.throw(1, 2, 3) 1956 gen.throw.assert_called_once_with(1, 2, 3) 2023 self._i += 1 2024: def throw(self, tp, *exc): 2025 self._i = 100 Lib/test/test_typing.py: 5349 pass 5350: def athrow(self, typ, val=None, tb=None): 5351 pass Lib/test/test_asyncio/test_pep492.py: 21 22: def throw(self, typ, val=None, tb=None): 23 pass Lib/test/test_lib2to3/test_fixers.py: 1041 def test_3(self): 1042: b = """g.throw(Exception, (5, 6, 7))""" 1043: a = """g.throw(Exception(5, 6, 7))""" 1044 self.check(b, a) 1061 def test_warn_3(self): 1062: s = """g.throw("foo", 5, 6)""" 1063 self.warns_unchanged(s, "Python 3 does not support string exceptions") 1082 b = """def foo(): 1083: g.throw(Exception, 5, 6)""" 1084 a = """def foo(): 1090 a = 5 1091: g.throw(Exception, 5, 6) 1092 b = 6""" 1100 b = """def foo(): 1101: g.throw(Exception,5,6)""" 1102 a = """def foo(): 1108 a = 5 1109: g.throw(Exception,5,6) 1110 b = 6""" 1118 b = """def foo(): 1119: g.throw(Exception, (5, 6, 7), 6)""" 1120 a = """def foo(): 1121: g.throw(Exception(5, 6, 7).with_traceback(6))""" 1122 self.check(b, a) 1126 a = 5 1127: g.throw(Exception, (5, 6, 7), 6) 1128 b = 6""" 1130 a = 5 1131: g.throw(Exception(5, 6, 7).with_traceback(6)) 1132 b = 6""" 1136 b = """def foo(): 1137: a + g.throw(Exception, 5, 6)""" 1138 a = """def foo(): 1144 a = 5 1145: a + g.throw(Exception, 5, 6) 1146 b = 6"""