0Pricing
Zig Academy · Ders

try ile Başarısızlıkları İletme

Tek bir anahtar sözcükle hataları üst katmana taşıyın.

try ile Başarısızlıkları İletme, CoddyKit'te ücretsiz bir Zig Academy dersidir. Bu, 4 dersinin 3. dersidir. Aşağıdan dersin tamamını ücretsiz okuyabilir, sonra tarayıcıda yerleşik kod editörü ve 7/24 yapay zeka koçu ile uygulamalı olarak pratik yapabilirsin. Bu, Zig Academy öğrenme yolunun bir parçasıdır ve ilerlemeniz web ve CoddyKit uygulaması arasında senkronize olur. Zig Academy kursu toplamda 4 dersten oluşur.

Bu dersin bazı bölümleri henüz çevrilmemiş olup İngilizce olarak gösterilmektedir.

Handling Gets Repetitive

Writing an if-else around every fallible call to forward its error gets noisy fast. Zig offers a shortcut: the try keyword.

try Unwraps or Returns

Put try before a fallible call. On success it hands you the value; on error it returns that error from your current function.

const n = try parse(input);

It Is Pure Sugar

That one line is exactly the same as catching the error and returning it yourself. try just writes the boilerplate for you.

const n = parse(input) catch |e| return e;

Your Function Must Be Fallible

Because try can return an error, the enclosing function needs an error union return type. Otherwise the compiler rejects it.

fn run() !void {
    const n = try parse(input);
}

Chain Many tries

Stack several try calls in a row. Each one stops the function early on failure, so the happy path reads top to bottom.

const f = try open(path);
const data = try read(f);

try in the Middle of Expressions

You can place try right inside a larger expression. The unwrapped value flows straight into the surrounding call or math.

const total = base + try parse(input);

try with void Calls

Even when a call returns !void, use try to forward any failure. You get no value back, only the early return on error.

try file.writeAll(data);

Errors Climb the Stack

With try in every layer, a failure deep down propagates all the way up until some caller finally decides to handle it.

Readable Happy Path

The big win is clarity: error forwarding fades into a single keyword, so the main logic stays front and center.

try Does Not Handle

Remember that try only forwards an error; it never recovers from one. To react locally you reach for catch instead.

When to Forward

Use try when the right move is to let the caller deal with failure. Most intermediate functions simply pass errors upward.

Quick Check

You write try doThing() inside a function. What happens if doThing returns an error?

Recap

You learned that try unwraps on success and returns the error otherwise. It is shorthand for catch and forward, keeping code clean. ✅

Sıkça Sorulan Sorular

“try ile Başarısızlıkları İletme” dersi ücretsiz mi?

Evet — “try ile Başarısızlıkları İletme” dersin tüm metni burada web'de ücretsiz olarak okunabilir. Etkileşimli olarak pratik yapmak (yerleşik kod editörü ve 7/24 yapay zeka koçu) ve Zig Academy kursunun geri kalanını açmak için CoddyKit PRO'ya yükselt. Zig Academy kursu toplamda 4 dersten oluşur.

“try ile Başarısızlıkları İletme” dersinde ne öğreneceğim?

Tek bir anahtar sözcükle hataları üst katmana taşıyın. Zig Academy ile uygulamalı kodu tarayıcıda doğrudan çalıştırarak pratik yaparsın ve 7/24 yapay zeka koçu dersi çalışırken sorularını yanıtlar.

Zig Academy öğrenmeye başlamak için deneyim gerekli mi?

Önceden deneyim gerekmez. CoddyKit'te Zig Academy, başlangıçtan ileri seviyeye kadar yapılandırıldığı için buradan başlayabilir veya başından başlayıp kendi hızında ilerleme yapabilirsin. Bu, 4 dersinin 3. dersidir.

“try ile Başarısızlıkları İletme” dersi ne kadar sürer?

Çoğu CoddyKit dersi yaklaşık 5–10 dakika sürer. Her biri kısa ve etkileşimli olduğu için sabit ilerleme yaparsın ve web ile uygulama arasında tam olarak bıraktığın yerden devam edebilirsin.

Bu Zig Academy dersinde kod yazıp çalıştırabilir miyim?

Evet. Her Zig Academy dersi yerleşik bir kod editörü içerir, bu sayede tarayıcıda gerçek kod yazıp çalıştırabilir ve anlık yapay zeka geri bildirimi alırsın — yerel kurulum gerekli değildir.

Bu kursun tüm dersleri

  1. Hata Kümeleri ve !T Birleşimi
  2. İşlevlerden Hata Döndürme
  3. try ile Başarısızlıkları İletme
  4. Çıkarılan Hata Kümeleri
← Zig Academy Sayfasına Dön