diff --git a/Src/IronPython.Modules/_warnings.cs b/Src/IronPython.Modules/_warnings.cs index ae37101c8..e343cff9e 100644 --- a/Src/IronPython.Modules/_warnings.cs +++ b/Src/IronPython.Modules/_warnings.cs @@ -260,7 +260,7 @@ internal static void showwarning(CodeContext context, object message, PythonType ((TextWriter)file).Write(text); } // unrecognized file type - warning is lost } - } catch (IOException) { + } catch (Exception ex) when (ex is IOException or OSException) { // invalid file - warning is lost } } diff --git a/Src/IronPython/Modules/_fileio.cs b/Src/IronPython/Modules/_fileio.cs index 5f299b655..e67592af3 100644 --- a/Src/IronPython/Modules/_fileio.cs +++ b/Src/IronPython/Modules/_fileio.cs @@ -305,10 +305,10 @@ public override void close(CodeContext/*!*/ context) { try { flush(context); - } catch (IOException) { - // flushing can fail, esp. if the other half of a pipe is closed - // ignore it because we're closing anyway - } + } catch (IOException) { /* ignore */ } catch (OSException) { /* ignore */ } + // flushing can fail, esp. if the other half of a pipe is closed + // ignore it because we're closing anyway + _closed = true; if (_closefd) {