Error handling, try...catch by diogoosz · Pull Request #466 · javascript-tutorial/pt.javascript.info
Repository navigation
Error handling, try...catch - #466
Merged
gabifs merged 2 commits into javascript-tutorial:master from diogoosz:translate-try-catch Nov 7, 2026
Merged
Error handling, try...catch #466 gabifs merged 2 commits into javascript-tutorial:master from diogoosz:translate-try-catch
Conversation
diogoosz commented Nov 4, 2026
Copy link Copy Markdown
Contributor
Tradução do artigo "Error handling, try...catch" para o português, incluindo o exercício.
Conforme comentado na #1 .
Translate 'Error handling, try...catch' article to Portuguese
72aaaf4
CLAassistant commented Nov 4, 2026 · edited Loading
Copy link Copy Markdown
|
|
View reviewed changes
gabifs left a comment
Copy link Copy Markdown
Contributor
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more .
Obrigado pela tradução! Deixei alguns comentários inline sobre estrangeirismos, trechos traduzidos de forma muito literal e strings que ficaram em inglês.
Diagrama: o try-catch-flow.svg continua com os textos em inglês ("Begin", "No Errors", "An error occured in the code", "Ignore catch block", "Ignore the rest of try", "Execute catch block"). Dá pra adicionar uma entrada no images.yml com as traduções? Por exemplo:
try-catch-flow.svg:
"Begin":
text: "Início"
position: center
"No Errors":
text: "Sem erros"
position: center
"An error occured in the code":
text: "Ocorreu um erro no código"
position: center
"Ignore catch block":
text: "Ignora o bloco catch"
position: center
"Ignore the rest of try":
text: "Ignora o resto do try"
position: center
"Execute catch block":
text: "Executa o bloco catch"
position: center
Comment thread
1-js/10-error-handling/1-try-catch/article.md
Outdated
| ``` | ||
|
|
||
| The JavaScript engine first reads the code, and then runs it. The errors that occur on the reading phase are called "parse-time" errors and are unrecoverable (from inside that code ). That's because the engine can't understand the code . | ||
| O motor do JavaScript primeiro lê o código, e só depois o executa. Os erros que ocorrem na fase de leitura são chamados de erros de "parse-time" (tempo de análise), e são irrecuperáveis (de dentro daquele código ). Isso acontece porque o motor não consegue entender o código . |
Outdated
| ``` | ||
|
|
||
| ## Optional "catch" binding | ||
| ## Ligação opcional do "catch" |
Outdated
| [recent browser=new] | ||
|
|
||
| If we don't need error details, `catch` may omit it : | ||
| Se não precisarmos dos detalhes do erro, o `catch` pode omiti-los : |
Outdated
| Geralmente ele é usado para decodificar dados recebidos pela rede, do servidor ou de outra fonte . | ||
|
|
||
| We receive it and call `JSON.parse` like this : | ||
| Nós recebemos e chamamos `JSON.parse` assim : |
Outdated
| ``` | ||
|
|
||
| Here we use the `catch` block only to show the message, but we can do much more: send a new network request, suggest an alternative to the visitor, send information about the error to a logging facility , ... . All much better than just dying . | ||
| Aqui usamos o bloco `catch` só pra mostrar a mensagem, mas podemos fazer muito mais: enviar uma nova requisição de rede, sugerir uma alternativa ao visitante, enviar informações sobre o erro pra um serviço de log , ... . Tudo isso é bem melhor do que simplesmente morrer . |
Outdated
| ``` | ||
|
|
||
| We can also get the error class name from `err.name` property. All native errors have it. Another option is to read `err.constructor.name`. | ||
| Também podemos obter o nome da classe do erro pela propriedade `err.name` . Todos os erros nativos têm ela. Outra opção é ler `err.constructor.name`. |
Outdated
| O erro lançado na linha `(*)` , de dentro do bloco `catch` , "cai fora" do `try...catch` e pode ser capturado por um `try...catch` externo (se existir ), ou mata o script. | ||
|
|
||
| So the `catch` block actually handles only errors that it knows how to deal with and "skips" all others . | ||
| Então o bloco `catch` , na verdade, só trata os erros que ele sabe como lidar, e "pula" todos os outros . |
Outdated
| } catch (err) { | ||
| *!* | ||
| alert( "External catch got: " + err ); // caught it ! | ||
| alert( "External catch got: " + err ); // capturou ! |
Outdated
| Aqui o `finally` garante que o tempo será medido corretamente nas duas situações -- tanto em caso de uma execução bem-sucedida do `fib` quanto em caso de erro nela : | ||
|
|
||
| ```js run | ||
| let num = +prompt("Enter a positive integer number?", 35) |
Outdated
| } | ||
|
|
||
| alert( func() ); // first works alert from finally, and then this one | ||
| alert( func() ); // primeiro funciona o alert do finally, e depois esse aqui |
Apply review suggestions from gabifs, translate try-catch-flow.svg
71d13e1
diogoosz commented Nov 7, 2026
Copy link Copy Markdown
Contributor
Author
|
Obrigado pela revisão detalhada, @gabifs ! Apliquei todas as sugestões de texto (estrangeirismos, traduções literais e strings que ficaram em inglês). Sobre o diagrama: montei o pipeline de tradução de imagens (server + engine + ImageMagick) e traduzi o |
62683f8
into
javascript-tutorial : master
Nov 7, 2026
1 check passed
gabifs
mentioned this pull request
Nov 7, 2026
Portuguese Translation Progress
#1
Open
Sign up for free
to join this conversation on GitHub .
Already have an account?
Sign in to comment