[9/9] Do not use bare "except"

Message ID 20240319-more-flake8-v1-9-893549dbed75@adacore.com
State New
Headers
Series Make gdb/python flake-clean |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gdb_build--master-aarch64 success Testing passed
linaro-tcwg-bot/tcwg_gdb_build--master-arm success Testing passed
linaro-tcwg-bot/tcwg_gdb_check--master-aarch64 success Testing passed
linaro-tcwg-bot/tcwg_gdb_check--master-arm success Testing passed

Commit Message

Tom Tromey March 19, 2024, 5:33 p.m. UTC
  flake8 warns about a bare "except".  The docs point out that this will
also catch KeyboardInterrupt and SystemExit exceptions, which is
normally undesirable.  Using "except Exception" catches everything
reasonable, so this patch makes this change.
---
 gdb/python/lib/gdb/__init__.py | 2 +-
 gdb/python/lib/gdb/styling.py  | 6 +++---
 2 files changed, 4 insertions(+), 4 deletions(-)
  

Patch

diff --git a/gdb/python/lib/gdb/__init__.py b/gdb/python/lib/gdb/__init__.py
index cff2f3afa49..e7d21fe8d27 100644
--- a/gdb/python/lib/gdb/__init__.py
+++ b/gdb/python/lib/gdb/__init__.py
@@ -157,7 +157,7 @@  def _auto_load_packages():
                         reload(__import__(modname))
                     else:
                         __import__(modname)
-                except:
+                except Exception:
                     sys.stderr.write(traceback.format_exc() + "\n")
 
 
diff --git a/gdb/python/lib/gdb/styling.py b/gdb/python/lib/gdb/styling.py
index 704c9926c29..8e5d64f15d9 100644
--- a/gdb/python/lib/gdb/styling.py
+++ b/gdb/python/lib/gdb/styling.py
@@ -39,7 +39,7 @@  try:
             return highlight(contents, lexer, formatter).encode(
                 gdb.host_charset(), "backslashreplace"
             )
-        except:
+        except Exception:
             return None
 
     class HandleNasmComments(TokenMergeFilter):
@@ -70,7 +70,7 @@  try:
             flavor = gdb.parameter("disassembly-flavor")
             if flavor == "intel" and gdbarch.name()[:4] == "i386":
                 lexer_type = "nasm"
-        except:
+        except Exception:
             # If GDB is built without i386 support then attempting to fetch
             # the 'disassembly-flavor' parameter will throw an error, which we
             # ignore.
@@ -89,7 +89,7 @@  try:
             lexer = __get_asm_lexer(gdbarch)
             formatter = get_formatter()
             return highlight(content, lexer, formatter).rstrip().encode()
-        except:
+        except Exception:
             return content
 
 except ImportError: