Skip to content

Commit 90397f7

Browse files
committed
translated until line 293
1 parent 8e97dfc commit 90397f7

File tree

1 file changed

+19
-19
lines changed

1 file changed

+19
-19
lines changed

1-js/11-async/08-async-await/article.md

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -196,21 +196,21 @@ new Waiter()
196196
Semnificația este aceeași: se asigură că valoarea returnată este o promisiune și permite `await`.
197197
198198
````
199-
## Error handling
199+
## Gestionarea erorilor
200200

201-
If a promise resolves normally, then `await promise` returns the result. But in the case of a rejection, it throws the error, just as if there were a `throw` statement at that line.
201+
Dacă o promisiune se rezolvă normal, atunci `await promise` returnează rezultatul. Dar în cazul unei respingeri, se aruncă eroarea, ca și cum ar exista o instrucțiune `throw` la linia respectivă.
202202

203-
This code:
203+
Acest cod:
204204

205205
```js
206206
async function f() {
207207
*!*
208-
await Promise.reject(new Error("Whoops!"));
208+
await Promise.reject(new Error("Uuups!"));
209209
*/!*
210210
}
211211
```
212212

213-
...is the same as this:
213+
...este la fel ca aceasta:
214214

215215
```js
216216
async function f() {
@@ -220,9 +220,9 @@ async function f() {
220220
}
221221
```
222222

223-
In real situations, the promise may take some time before it rejects. In that case there will be a delay before `await` throws an error.
223+
În situații reale, promisiunea poate dura ceva timp înainte de a fi respinsă. În acest caz va exista o întârziere înainte ca `await` să arunce o eroare.
224224

225-
We can catch that error using `try..catch`, the same way as a regular `throw`:
225+
Putem prinde această eroare folosind `try..catch`, la fel ca un `throw` obișnuit:
226226

227227
```js run
228228
async function f() {
@@ -239,7 +239,7 @@ async function f() {
239239
f();
240240
```
241241

242-
In the case of an error, the control jumps to the `catch` block. We can also wrap multiple lines:
242+
În cazul unei erori, controlul sare la blocul `catch`. Putem de asemenea să înfășurăm mai multe linii:
243243

244244
```js run
245245
async function f() {
@@ -248,49 +248,49 @@ async function f() {
248248
let response = await fetch('/no-user-here');
249249
let user = await response.json();
250250
} catch(err) {
251-
// catches errors both in fetch and response.json
251+
// prinde erorile atât din fetch cât și din response.json
252252
alert(err);
253253
}
254254
}
255255

256256
f();
257257
```
258258

259-
If we don't have `try..catch`, then the promise generated by the call of the async function `f()` becomes rejected. We can append `.catch` to handle it:
259+
Dacă nu avem `try..catch`, atunci promisiunea generată de apelarea funcției asincrone `f()` devine respinsă. Putem adăuga `.catch` pentru a o gestiona:
260260

261261
```js run
262262
async function f() {
263263
let response = await fetch('http://no-such-url');
264264
}
265265

266-
// f() becomes a rejected promise
266+
// f() devine o promisiune respinsă
267267
*!*
268268
f().catch(alert); // TypeError: failed to fetch // (*)
269269
*/!*
270270
```
271271

272-
If we forget to add `.catch` there, then we get an unhandled promise error (viewable in the console). We can catch such errors using a global `unhandledrejection` event handler as described in the chapter <info:promise-error-handling>.
272+
Dacă uităm să adăugăm `.catch` acolo, atunci vom primi o eroare de promisiune negestionată (vizualizabilă în consolă). Putem prinde astfel de erori folosind un gestionar de evenimente global `unhandledrejection`, așa cum este descris în capitolul <info:promise-error-handling>.
273273

274274

275-
```smart header="`async/await` and `promise.then/catch`"
276-
When we use `async/await`, we rarely need `.then`, because `await` handles the waiting for us. And we can use a regular `try..catch` instead of `.catch`. That's usually (but not always) more convenient.
275+
```smart header="`async/await` și `promise.then/catch`"
276+
Atunci când folosim `async/await`, rareori avem nevoie de `.then`, deoarece `await` se ocupă de așteptare în locul nostru. Și putem folosi un `try..catch` obișnuit în loc de `.catch`. Acest lucru este de obicei (dar nu întotdeauna) mai convenabil.
277277

278-
But at the top level of the code, when we're outside any `async` function, we're syntactically unable to use `await`, so it's a normal practice to add `.then/catch` to handle the final result or falling-through error, like in the line `(*)` of the example above.
278+
Dar la nivelul superior al codului, atunci când ne aflăm în afara oricărei funcții `async`, nu putem ca sintactic să folosim `await`, așa că este o practică normală să adăugăm `.then/catch` pentru a gestiona rezultatul final sau eroarea în cădere, ca în linia `(*)` din exemplul de mai sus.
279279
```
280280
281-
````smart header="`async/await` works well with `Promise.all`"
282-
When we need to wait for multiple promises, we can wrap them in `Promise.all` and then `await`:
281+
````smart header="`async/await` funcționează bine cu `Promise.all`"
282+
Atunci când trebuie să așteptăm mai multe promisiuni, le putem înfășura în `Promise.all` și apoi `await`:
283283
284284
```js
285-
// wait for the array of results
285+
// așteptă matricea de rezultate
286286
let results = await Promise.all([
287287
fetch(url1),
288288
fetch(url2),
289289
...
290290
]);
291291
```
292292

293-
In the case of an error, it propagates as usual, from the failed promise to `Promise.all`, and then becomes an exception that we can catch using `try..catch` around the call.
293+
În cazul unei erori, aceasta se propagă ca de obicei, de la promisiunea eșuată la `Promise.all`, iar apoi devine o excepție pe care o putem prinde folosind `try..catch` în jurul apelului.
294294

295295
````
296296

0 commit comments

Comments
 (0)