Kaydet (Commit) 5226aeea authored tarafından Ali GOREN's avatar Ali GOREN

Hata Yakalama çevirildi

üst ccca9ec4
...@@ -1796,41 +1796,37 @@ async function temizKodMakalesiniAl() { ...@@ -1796,41 +1796,37 @@ async function temizKodMakalesiniAl() {
**[⬆ en başa dön](#içindekiler)** **[⬆ en başa dön](#içindekiler)**
## **Error Handling** ## **Hata Yakalama**
Thrown errors are a good thing! They mean the runtime has successfully Hatalar oluşturmak iyi bir şeydir. Hatalar size programınızda bir şeylerin yolunda olmadığını söylemenin en iyi yoludur.
identified when something in your program has gone wrong and it's letting Çalışan bir kod parçacığı ya da çalışmayı durduran bir fonksiyonun, process'in neden durduğuna dair konsol ekranında sizi bilgilendirirler.
you know by stopping function execution on the current stack, killing the
process (in Node), and notifying you in the console with a stack trace. ### Yakalanan Hataları Görmezden Gelmeyin
Yakalanan bir hata ile hiçbir şey gerçekleştirmemek, size o hatayı tamamen fixlemiş olma imkanı sunmaz.
### Don't ignore caught errors Hataları (`console.log`) ile göstermek, tıpkı suya yazı yazmak gibidir. Çoğu zaman yetersizdir.
Doing nothing with a caught error doesn't give you the ability to ever fix Eğer kod bölümlerini `try/catch` blokları ile oluşturuyorsanız o bölümde bir hatanın oluşabileceğini düşünüyorsunuzdur.
or react to said error. Logging the error to the console (`console.log`) Bu durumlar için bir planınız olmalı ya da bu durumları yönetebileceğiniz ayrı kod yapılarınız olmalı.
isn't much better as often times it can get lost in a sea of things printed
to the console. If you wrap any bit of code in a `try/catch` it means you
think an error may occur there and therefore you should have a plan,
or create a code path, for when it occurs.
**Kötü:** **Kötü:**
```javascript ```javascript
try { try {
functionThatMightThrow(); hataFirlatabilecekFonksiyon();
} catch (error) { } catch (hata) {
console.log(error); console.log(hata);
} }
``` ```
**İyi:** **İyi:**
```javascript ```javascript
try { try {
functionThatMightThrow(); hataFirlatabilecekFonksiyon();
} catch (error) { } catch (hata) {
// One option (more noisy than console.log): // İlk seçenek (console.log'dan daha çok bilgilendirici):
console.error(error); console.error(hata);
// Another option: // Diğer Seçenek:
notifyUserOfError(error); kullaniciyaHataGoster(hata);
// Another option: // Diğer Seçenek:
reportErrorToService(error); hatayiServiseBildir(hata);
// OR do all three! // Ya da üçünü de yapabilirsiniz!!
} }
``` ```
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment