@@ -85,6 +85,7 @@ def MakeNewException(self):
8585 ExceptionInfo ('Exception' , 'IronPython.Runtime.Exceptions.PythonException' , None , (), (
8686 ExceptionInfo ('StopIteration' , 'IronPython.Runtime.Exceptions.StopIterationException' , None , ('value' ,), ()),
8787 ExceptionInfo ('StopAsyncIteration' , 'IronPython.Runtime.Exceptions.StopAsyncIterationException' , None , ('value' ,), ()),
88+ ExceptionInfo ('CancelledError' , 'System.OperationCanceledException' , None , (), ()),
8889 ExceptionInfo ('ArithmeticError' , 'System.ArithmeticException' , None , (), (
8990 ExceptionInfo ('FloatingPointError' , 'IronPython.Runtime.Exceptions.FloatingPointException' , None , (), ()),
9091 ExceptionInfo ('OverflowError' , 'System.OverflowException' , None , (), ()),
@@ -261,16 +262,26 @@ def gen_topython_helper(cw):
261262 cw .exit_block ()
262263
263264
265+ _clr_name_overrides = {
266+ 'CancelledError' : 'OperationCanceledException' ,
267+ }
268+
264269def get_clr_name (e ):
270+ if e in _clr_name_overrides :
271+ return _clr_name_overrides [e ]
265272 return e .replace ('Error' , '' ) + 'Exception'
266273
267274FACTORY = """
268275internal static Exception %(name)s(string message) => new %(clrname)s(message);
269276public static Exception %(name)s(string format, params object?[] args) => new %(clrname)s(string.Format(format, args));
270277""" .rstrip ()
271278
279+ # Exceptions that map to existing CLR types (no generated CLR class needed),
280+ # but still need factory methods in PythonOps.
281+ _factory_only_exceptions = ['CancelledError' ]
282+
272283def factory_gen (cw ):
273- for e in pythonExcs :
284+ for e in pythonExcs + _factory_only_exceptions :
274285 cw .write (FACTORY , name = e , clrname = get_clr_name (e ))
275286
276287CLASS1 = """\
0 commit comments