Exception Handling guideline- Python vs Java

前端 未结 3 429
故里飘歌
故里飘歌 2021-01-12 02:29

I am original Java developer, for me, checked Exception in Java is obviously/easy enough for me to decide to catch or throw it to the caller to handle later. Then it comes P

3条回答
  •  余生分开走
    2021-01-12 02:44

    1. Best practice is to handle appropriate exceptions in the appropriate place. Only you, as developer, can decide which part of your code should catch exceptions. This should become apparent with decent unit testing. If you have unhandled exceptions, they will show up.

    2. You already described the differences. At a more fundamental level, Java's designers think they know better than you how you should code, and they'll force you to write lots of it. Python, by contrast, assumes that you are an adult, and that you know what you want to do. This means that you can shoot yourself in the foot if you insist on so doing.

提交回复
热议问题