Python Exception Handling, Return it or Raise it ? #30
Replies: 7 comments 2 replies
-
我是指單一檔案內避免混用raise exceptions 與return error
實務上可根據需要選擇合適的錯誤處理方式,例如我認為業務邏輯部份使用拋出異常,外部介面使用返回錯誤,讓系統有清晰一致的錯誤處理機制,以目前專案目錄結構為例,可能是:
|
Beta Was this translation helpful? Give feedback.
-
OK , here is my thought about the issue Raise Exception
Return exception
About this game projectFor domain models , the error MAY or MAY NOT be crucial :
The questions now are :
For repositories , the error is mostly crucial :
For use-case layer
For DTO and presenters
|
Beta Was this translation helpful? Give feedback.
-
從我前面的論述,應該看的出來是從整體架構方面去思考 如果「層」沒有統一的error handling話,像這邊我就會需要去檢查下面每個呼叫到的方法,是否都是使用Return exception,所以可以直接用 |
Beta Was this translation helpful? Give feedback.
-
@wingtkw , please let us know about your thought in this coding issue, |
Beta Was this translation helpful? Give feedback.
-
@teds-lin , let us wait for Wing's reply by the end of the day (23:59:59, 8th. Nov. 2023) , @wingtkw , please spend few minutes describing your thought on this issue , |
Beta Was this translation helpful? Give feedback.
-
My opinion towards return exception or raise exception are quite similar to you two |
Beta Was this translation helpful? Give feedback.
-
RecapIn this game app we transfer the error in following manner :
|
Beta Was this translation helpful? Give feedback.
-
Hi , @teds-lin and @wingtkw
as the lines of code increases and the application has been getting complicated,
it is time to decide whether we should always raise exceptions or return them, or any other hybrid approach.
I am reading the articles to see whether I can come up with some good practice for this game application.
I never thought questions like this,
if you know any good-quality article or discussion threads, please post links at here,
you can also leave comments in this thread, I'll appreciate any feedback.
I would also probably ask similar questions in other online Python communities.
Thanks
Beta Was this translation helpful? Give feedback.
All reactions