Risky catches increase production risks
class MyException(object): def __init__(self, code, message): self.code = code self.message = message try: if 1 != 0: raise MyException(42, "1 != 0 Exception") except MyException as e: print(e.message)
lass MyException(Exception): def __init__(self, code, message): self.code = code self.message = message try: if 1 != 0: raise MyException(1244, "1 != 0 Exception") except MyException as e: print(e.message)
Why you should care
BaseExceptionat the lowest level. User-defined exception classes should actually inherit from
Exception; they shouldn’t directly inherit from
BaseException. Python requires all exception classes to inherit from a base exception superclass to ensure that they all meet the minimum required interface needed to be useful.
Highlight will consider that each classes whose name ends with “Exception” or “Error” is an exception class. This will be statically right, and is acceptable because Highlight is a statistical tool.
Through this rule, Highlight will check that all exceptions classes are derived from the builtin BaseException (but never directly !).
About CAST and Highlight’s Code Insights
Over the last 25 years, CAST has leveraged unique knowledge on software quality measurement by analyzing thousands of applications and billions of lines of code. Based on this experience and community standards on programming best practices, Highlight implements hundreds of code insights across 15+ technologies to calculate health factors of a software.