selfteaching / selfteaching/selfteaching-python-camp

Day09 Try-raise-except和Try-catch-throw之间的对比

Open
#668 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
151
Forks
875
PR merge metrics
No merged PRs in 30d

Description

刚刚看同学们的issues,我突然想进一步去了解一下异常处理这个东西。以前学其它语言的时候异常处理是Try-catch-throw,老师当时提了一句可以把要执行的语句都先放在try里面,当时觉得异常处理不重要就没当回事,也没有敲代码验证一下,所以这一块知识还是比较薄弱的。
对比:
二者都有try,只不过python还有else,如果没有异常可以把代码放到else里,另一个则都在try中;python的raise很多情况下应该都是要与if同时出现,而catch会自动捕获异常,并在代码段里执行语句,这一部分功能有些许像except;到了python中的except,可以写print等语句,尽可能详细地描述异常,而throw则只是抛出异常地功能;python中还有finally,无论异常与否都会执行的一个语句。
因为Try-catch-throw学得确实不太好,语法是刚刚才查的,有什么不对的,还望教练和同学们指出。

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

No file, test, or entry point is named; start by clarifying whether this discussion should become a documentation change. Done would require an agreed scope and a specific location for the comparison, which the issue does not currently provide.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
documentation
Issue type
Documentation
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
10/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.