SlideShare una empresa de Scribd logo
1 de 24
Exception Handling
Güven Şahin
guvensahin.com
Exception Nedir ?
• Bir programın derleme(compile-time) veya
çalışma zamanında(run-time) ortaya çıkan
istisnalara, beklenmedik durumlara verilen
isimdir.
Exception
Exception’lar pek çok değişik sebepten dolayı
üretilebilirler. Bunlar:
• Kullanıcı kaynaklı
• Mantıksal
• Sistemsel
...olabilirler.
Örnek Exception’lar
• Kullanıcı geçerli olmayan bir veri girebilir.
• Açılmak istenen veya sayfaya dahil edilmek
istenen dosya bulunmayabilir.
• İşlemin ortasında internet bağlantısı
sonlanabilir.
• Veritabanı işlemi sırasında veritabanına
ulaşılamayabilinir vb.
Exception Handling Nedir ?
• Çalışma zamanında ortaya çıkan istisnai ve
beklenmedik durumların programlama dilinde
algılanması,
• Duruma göre programın akışının buna göre
düzenlenmesine,
• Hataların kotarılmasına exception handling
denir.
Hata yakalama mekanizması
• İleri seviye programlama dillerinde try, catch
vb. istisna(exception) yakalama ifadeleri
geliştirilmiştir.
• Bu ifadelere sırasıyla değinelim:
Try
• Try bloğu içerisinde kaynak kodlarımız yer alır.
Bu blok içerisinde olası bir exception, catch
bloğuna yönlendirilir.
Catch
• Catch bloğu, istisnai
durumun yakalandığı
ve bunun sonucunda
ne yapılacağını
belirttiğimiz kısımdır.
Catch
• Catch bloğu birden fazla kullanılabilir. Farklı
Exception’larda programın akışını farklı düzenlemek
isteyebiliriz. Örnek c# kodu:
Örnek Try/Catch bloğu
• Şimdi javascript örneği inceleyelim.
• Karşılaştığımız belli durumlar, her
programlama dilinde aynı tepkiyi vermez.
• Örneğin sıfıra bölünme hatası(10 / 0)
javascript ve php’de kod akışını durdurmazken
c#’da DivisionByZero exception’ının
tetiklenmesine sebebiyet veriyor.
Farklı diller farklı exception’lar...
Farklı diller farklı exception’lar...
• Örneğin tanımlı olmayan bir fonksiyonu çağırmak
javascript’te bir exception’a sebep olurken php de
bir fatal error’a sebebiyet veriyor ve bütün kod
akışı duruyor.
Throw
• Throw, fırlatmak demektir. Bir istisnayı manuel
olarak göndermek istediğimizde kullanırız.
• Gönderilen istisna yine Catch bloğu tarafından
yakalanır.
• C tabanlı dillerde sintaksı genel olarak şuna
benzemektedir:
• throw new Exception(‘Örnek Mesaj’);
• Şimdi javascript ve php örnekleri inceleyelim.
Finally
• Try ve Catch blokları çalıştıktan sonra her
şekilde ne olursa olsun çalışacak kodlarımız
buraya yazılır.
• Finally bloğu genellikle bazı kaynakları serbest
bırakmak için kullanılır.
Retry
• Finally gibi bu ifade de her programlama
dilinde bulunmayabilir. Sadece Catch bloğuna
yazılır.
• Görevi ise Try içindeki kodu tekrardan
çalıştırmaktır. Genellikle veritabanı
işlemlerinde transaction’ı tekrardan
tetiklemek içindir.
• X++ içinde max 5 defa kullanılabilir.
Retry Örnek Kod Bloğu – X++
Örnek Exception Class’ı
• Kendi exception class’ımızı türettiğimiz ve
birden fazla catch bloğu eklediğimiz php
örneğimizi inceleyelim.
Hata Yönetimi
• Veritabanı, dosya okuma-yazma gibi istisnaya,
hataya yatkın yerlerde try/catch bloklarımızı
yerleştirip hataları yönetmeliyiz.
• Aynı zamanda uygulamada alınan
exception’ları loglamak iyi bir alışkanlıktır.
Hata Yönetimi - Log
• Uygulamanın çalıştırılma ortamı(server vb)
değiştiğinde,
• Veya uygulamayı bir ekiple birlikte
geliştiriyorsanız ve devamlı diğer
fonksiyonaliteleri etkileyebilecek değişiklikler
yapılıyorsa,
• Bunlara benzer durumlarda loglarınıza bakarak
exception’ın kaynağını bulabilirsiniz.
Teşekkürler
• Güven Şahin tarafından hazırlanmıştır.
• http://guvensahin.com
• http://blog.guvensahin.com

Más contenido relacionado

Destacado

Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Applitools
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at WorkGetSmarter
 
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...DevGAMM Conference
 
Barbie - Brand Strategy Presentation
Barbie - Brand Strategy PresentationBarbie - Brand Strategy Presentation
Barbie - Brand Strategy PresentationErica Santiago
 
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them wellGood Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them wellSaba Software
 

Destacado (20)

Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work
 
ChatGPT webinar slides
ChatGPT webinar slidesChatGPT webinar slides
ChatGPT webinar slides
 
More than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike RoutesMore than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike Routes
 
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
 
Barbie - Brand Strategy Presentation
Barbie - Brand Strategy PresentationBarbie - Brand Strategy Presentation
Barbie - Brand Strategy Presentation
 
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them wellGood Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
 

Exception Handling - Mayıs 2013 - Güven Şahin

  • 2. Exception Nedir ? • Bir programın derleme(compile-time) veya çalışma zamanında(run-time) ortaya çıkan istisnalara, beklenmedik durumlara verilen isimdir.
  • 3. Exception Exception’lar pek çok değişik sebepten dolayı üretilebilirler. Bunlar: • Kullanıcı kaynaklı • Mantıksal • Sistemsel ...olabilirler.
  • 4. Örnek Exception’lar • Kullanıcı geçerli olmayan bir veri girebilir. • Açılmak istenen veya sayfaya dahil edilmek istenen dosya bulunmayabilir. • İşlemin ortasında internet bağlantısı sonlanabilir. • Veritabanı işlemi sırasında veritabanına ulaşılamayabilinir vb.
  • 5. Exception Handling Nedir ? • Çalışma zamanında ortaya çıkan istisnai ve beklenmedik durumların programlama dilinde algılanması, • Duruma göre programın akışının buna göre düzenlenmesine, • Hataların kotarılmasına exception handling denir.
  • 6.
  • 7. Hata yakalama mekanizması • İleri seviye programlama dillerinde try, catch vb. istisna(exception) yakalama ifadeleri geliştirilmiştir. • Bu ifadelere sırasıyla değinelim:
  • 8. Try • Try bloğu içerisinde kaynak kodlarımız yer alır. Bu blok içerisinde olası bir exception, catch bloğuna yönlendirilir.
  • 9. Catch • Catch bloğu, istisnai durumun yakalandığı ve bunun sonucunda ne yapılacağını belirttiğimiz kısımdır.
  • 10. Catch • Catch bloğu birden fazla kullanılabilir. Farklı Exception’larda programın akışını farklı düzenlemek isteyebiliriz. Örnek c# kodu:
  • 12. • Şimdi javascript örneği inceleyelim.
  • 13. • Karşılaştığımız belli durumlar, her programlama dilinde aynı tepkiyi vermez. • Örneğin sıfıra bölünme hatası(10 / 0) javascript ve php’de kod akışını durdurmazken c#’da DivisionByZero exception’ının tetiklenmesine sebebiyet veriyor. Farklı diller farklı exception’lar...
  • 14. Farklı diller farklı exception’lar... • Örneğin tanımlı olmayan bir fonksiyonu çağırmak javascript’te bir exception’a sebep olurken php de bir fatal error’a sebebiyet veriyor ve bütün kod akışı duruyor.
  • 15. Throw • Throw, fırlatmak demektir. Bir istisnayı manuel olarak göndermek istediğimizde kullanırız. • Gönderilen istisna yine Catch bloğu tarafından yakalanır. • C tabanlı dillerde sintaksı genel olarak şuna benzemektedir: • throw new Exception(‘Örnek Mesaj’);
  • 16. • Şimdi javascript ve php örnekleri inceleyelim.
  • 17. Finally • Try ve Catch blokları çalıştıktan sonra her şekilde ne olursa olsun çalışacak kodlarımız buraya yazılır. • Finally bloğu genellikle bazı kaynakları serbest bırakmak için kullanılır.
  • 18. Retry • Finally gibi bu ifade de her programlama dilinde bulunmayabilir. Sadece Catch bloğuna yazılır. • Görevi ise Try içindeki kodu tekrardan çalıştırmaktır. Genellikle veritabanı işlemlerinde transaction’ı tekrardan tetiklemek içindir. • X++ içinde max 5 defa kullanılabilir.
  • 19. Retry Örnek Kod Bloğu – X++
  • 20. Örnek Exception Class’ı • Kendi exception class’ımızı türettiğimiz ve birden fazla catch bloğu eklediğimiz php örneğimizi inceleyelim.
  • 21. Hata Yönetimi • Veritabanı, dosya okuma-yazma gibi istisnaya, hataya yatkın yerlerde try/catch bloklarımızı yerleştirip hataları yönetmeliyiz. • Aynı zamanda uygulamada alınan exception’ları loglamak iyi bir alışkanlıktır.
  • 22. Hata Yönetimi - Log • Uygulamanın çalıştırılma ortamı(server vb) değiştiğinde, • Veya uygulamayı bir ekiple birlikte geliştiriyorsanız ve devamlı diğer fonksiyonaliteleri etkileyebilecek değişiklikler yapılıyorsa, • Bunlara benzer durumlarda loglarınıza bakarak exception’ın kaynağını bulabilirsiniz.
  • 24. • Güven Şahin tarafından hazırlanmıştır. • http://guvensahin.com • http://blog.guvensahin.com

Notas del editor

  1. Derlemeye örnek olarak Oracle PL/SQL verilebilir.
  2. Türkçesi:istisna yönetimi,Hata yönetimi,Hata yakalama olabilir.Hata yakalama mekanizması platform bağımsızdır.
  3. Try-Catch
  4. Birden fazla catch bloğu kullanılabilir.
  5. Tanımlı olmayan fonksiyona js exception fırlatırken php fatal error veriyor.Veya sıfıra bölünme istisnasında
  6. Önce phpSonra javascript
  7. Dynamics AX’da bu blok bulunmamaktadır.Örneğin try bloğunda bir dosya açtınız, eğer bir hata oluşursa try bloğu içinde dosyayı kapatma kodu çalışmadan catche atlar ve sonuçta dosyanız kapanmaz. Bu durumda siz dosya kapatma işlemini finally bloğunda yapacak olursanız her halükarda dosyanızın kapanmasını garanti altına almış olursunuz.
  8. Retry 5 kaynağı inside dynamics ax 2009 sayfa 518.....an UpdateConfl ictNotRecovered exception. In Dynamics AX, the maximum number of retries, which is set in the OCCRetryCount macro element in the AOT, is 5.
  9. Görüleceği üzere extend ettiğimiz Exception class’ının methodları olan getLine(),getFile(),getMessage() vb. Lerini kullanabiliyoruz.