try/except ile Yakalama
Bir başarısızlıktan kontrollü biçimde kurtulun.
try/except ile Yakalama, CoddyKit'te ücretsiz bir Mojo Academy dersidir. Bu, 4 dersinin 2. 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, Mojo Academy öğrenme yolunun bir parçasıdır ve ilerlemeniz web ve CoddyKit uygulaması arasında senkronize olur. Mojo Academy kursu toplamda 4 dersten oluşur.
Bu dersin bazı bölümleri henüz çevrilmemiş olup İngilizce olarak gösterilmektedir.
Catching the Fall
Raising signals a problem, but someone must catch it. Mojo uses a try block to run risky code and recover if it fails. 🪤
The try Block
Code that might fail goes inside try. If it raises, Mojo jumps straight to the matching recovery code below.
try:
risky_step()The except Block
The except block holds your recovery plan. It only runs when the try block actually raised an error.
try:
risky_step()
except:
print("recovered")Reading the Error
You can name the caught error to read its message. Here e holds the details of what went wrong.
try:
risky_step()
except e:
print("failed:", e)Normal Path First
If nothing raises, the try block finishes and the except block is skipped entirely. The happy path stays clean.
Recovering Gracefully
Catching lets you show a friendly message or use a fallback value instead of letting the whole program crash. ✨
Keep try Blocks Small
Wrap only the risky line in try, not your whole function. Small blocks make it clear what could fail.
Catching Calls That Raise
Calling a function that may raise requires a try. Here we safely attempt a withdrawal and handle a rejection.
try:
withdraw(-5)
except e:
print("denied:", e)Don't Swallow Silently
An empty except that does nothing hides bugs. At minimum log the error so problems stay visible.
Catch Where You Can Help
Only catch an error where you can actually do something useful about it. Otherwise let it propagate upward.
Try Plus Except as a Pair
Together try and except turn a possible failure into a controlled outcome your program can continue past.
Quick Check
Recall when each block of a try/except actually runs.
Recap
You learned to wrap risky code in try, recover in except, read the error with a name, and keep blocks small and meaningful. 🎯
Sıkça Sorulan Sorular
“try/except ile Yakalama” dersi ücretsiz mi?
Evet — “try/except ile Yakalama” 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 Mojo Academy kursunun geri kalanını açmak için CoddyKit PRO'ya yükselt. Mojo Academy kursu toplamda 4 dersten oluşur.
“try/except ile Yakalama” dersinde ne öğreneceğim?
Bir başarısızlıktan kontrollü biçimde kurtulun. Mojo 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.
Mojo Academy öğrenmeye başlamak için deneyim gerekli mi?
Önceden deneyim gerekmez. CoddyKit'te Mojo 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 2. dersidir.
“try/except ile Yakalama” 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 Mojo Academy dersinde kod yazıp çalıştırabilir miyim?
Evet. Her Mojo 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
- Hata Oluşturma
- try/except ile Yakalama
- raises Açıklaması
- finally ile Temizleme