Re: Read-only error
Karsten Hilbert via Python-list <[email protected]> Tue, 14 Jul 2026 17:24:41 +0200
| Newsgroups | gmane.comp.python.general |
|---|---|
| Message-ID | <[email protected]> |
Am Tue, Jul 14, 2026 at 10:05:32AM -0400 schrieb Random832: > The problem is that if Python wants to provide information > that isn't provided in the error code from the operating > system, it has to do a complex and potentially expensive > root cause analysis on its own, checking for all the > possible conditions that could have caused the error. Do you > do this every time there is an error, or only when > requested? having it be a subclass rather than a property > makes 'only when requested' more difficult to design. It could be try: provoke_PermissionError() except PermissionError as e: try: root_cause = e.do_root_cause_analysis_even_if_it_takes_some_effort(maybe_list_of_potential_causes_to_check) except: report_issue() raise e match root_cause: case FileReadOnlyError: raise MyFancyReadOnlyErrorOrSomeSuch(further_information) case_: raise e so I'll pay the dividend only when I am (or my users are) prepared to do so. > And what if a secondary error is encounted while doing the > analysis [e.g. you can't stat the file]? Just like now: >>> try: ... 1 / 0 ... except Exception: ... 100 / 0 ... Traceback (most recent call last): File "<stdin>", line 2, in <module> ZeroDivisionError: division by zero During handling of the above exception, another exception occurred: Traceback (most recent call last): File "<stdin>", line 4, in <module> ZeroDivisionError: division by zero Karsten -- GPG 40BE 5B0E C98E 1713 AFA6 5BC0 3BEA AC80 7D4F C89B