GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Error handling, try...catch by diogoosz · Pull Request #466 · javascript-tutorial/pt.javascript.info

Conversation

@diogoosz

@diogoosz 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.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@diogoosz
Translate 'Error handling, try...catch' article to Portuguese
72aaaf4
@CLAassistant

CLAassistant commented Nov 4, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

gabifs
gabifs reviewed Nov 7, 2026
View reviewed changes

@gabifs gabifs left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

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

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
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.

@gabifs gabifs Nov 7, 2026

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Acho que dá pra tirar o termo em inglês e deixar só a tradução:

Suggested change
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.
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 "tempo de análise" (*parse-time*), e são irrecuperáveis (de dentro daquele código). Isso acontece porque o motor não consegue entender o código.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread 1-js/10-error-handling/1-try-catch/article.md Outdated
```

## Optional "catch" binding
## Ligação opcional do "catch"

@gabifs gabifs Nov 7, 2026

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Ligação" é tradução literal de binding e fica confuso pra quem lê. Que tal:

Suggested change
## Ligação opcional do "catch"
## Parâmetro opcional do "catch"

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread 1-js/10-error-handling/1-try-catch/article.md 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:

@gabifs gabifs Nov 7, 2026

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No original, "catch may omit it" quer dizer que o parâmetro (err) pode ser omitido, e não os detalhes do erro. Sugestão:

Suggested change
Se não precisarmos dos detalhes do erro, o `catch` pode omiti-los:
Se não precisarmos dos detalhes do erro, o `catch` pode omitir o parâmetro:

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread 1-js/10-error-handling/1-try-catch/article.md 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:

@gabifs gabifs Nov 7, 2026

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A frase ficou sem objeto (recebemos o quê?):

Suggested change
Nós recebemos e chamamos `JSON.parse` assim:
Recebemos os dados e chamamos `JSON.parse` assim:

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread 1-js/10-error-handling/1-try-catch/article.md 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.

@gabifs gabifs Nov 7, 2026

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pra evitar estrangeirismo:

Suggested change
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.
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 registro, ... . Tudo isso é bem melhor do que simplesmente morrer.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread 1-js/10-error-handling/1-try-catch/article.md 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`.

@gabifs gabifs Nov 7, 2026

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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`.
Também podemos obter o nome da classe do erro pela propriedade `err.name`. Todos os erros nativos a possuem. Outra opção é ler `err.constructor.name`.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread 1-js/10-error-handling/1-try-catch/article.md 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.

@gabifs gabifs Nov 7, 2026

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Falta a preposição que o "lidar" pede:

Suggested change
Então o bloco `catch`, na verdade, só trata os erros que ele sabe como lidar, e "pula" todos os outros.
Então o bloco `catch`, na verdade, só trata os erros com que sabe lidar, e "pula" todos os outros.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread 1-js/10-error-handling/1-try-catch/article.md Outdated
} catch (err) {
*!*
alert( "External catch got: " + err ); // caught it!
alert( "External catch got: " + err ); // capturou!

@gabifs gabifs Nov 7, 2026

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

O comentário foi traduzido, mas a string não:

Suggested change
alert( "External catch got: " + err ); // capturou!
alert( "Catch externo capturou: " + err ); // capturou!

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread 1-js/10-error-handling/1-try-catch/article.md 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)

@gabifs gabifs Nov 7, 2026

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As strings desse exemplo continuam em inglês ("Enter a positive integer number?", "Must not be negative, and also an integer.", "error occurred", `execution took ${diff}ms`), mas o texto logo abaixo pede pro leitor digitar 35 no prompt. Sugestão: "Digite um número inteiro positivo:", "Não pode ser negativo, e deve ser inteiro.", "ocorreu um erro", `a execução levou ${diff}ms`.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread 1-js/10-error-handling/1-try-catch/article.md Outdated
}

alert( func() ); // first works alert from finally, and then this one
alert( func() ); // primeiro funciona o alert do finally, e depois esse aqui

@gabifs gabifs Nov 7, 2026

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"funciona" ficou literal demais (vem de "first works alert from finally"):

Suggested change
alert( func() ); // primeiro funciona o alert do finally, e depois esse aqui
alert( func() ); // primeiro executa o alert do finally, e depois este

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@diogoosz
Apply review suggestions from gabifs, translate try-catch-flow.svg
71d13e1
@diogoosz

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 try-catch-flow.svg usando exatamente o images.yml que você sugeriu. Deve aparecer certinho agora.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@gabifs
gabifs merged commit 62683f8 into javascript-tutorial:master Nov 7, 2026
1 check passed

Uh oh!

There was an error while loading. Please reload this page.

@gabifs 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

Reviewers

@gabifs gabifs gabifs left review comments

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

3 participants

@diogoosz @CLAassistant @gabifs
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.