SlideShare a Scribd company logo
1 of 18
Understanding
Exception Handling in .net.

Presenter: Harsh Wardhan, Mindfire Solutions
Date: 29/10/2013
Agenda
- What is Exception?
- The try, the catch & the finally.
- A look into System.Exception class.
- Throwing Exception.
- Defining your own exception class.
- Best practices.
- Unhandled Exceptions.
- Debugging Exceptions.
Presenter: Harsh Wardhan, Mindfire Solutions
What is Exception?
- When a member fails to complete the task it is
supposed to perform as indicated by its name, it is
called an exception.

Presenter: Harsh Wardhan, Mindfire Solutions
The Try
- A Try block contains code that require:
- Common clean up operations.
- Exception recovery operations.
- A code that might potentially throw an
exception.
- A Try block should have at least one catch or finally
block associated with it.
- How much code should be added in a single try
block?
Presenter: Harsh Wardhan, Mindfire Solutions
The Catch
- Contains code to execute in response to an
exception.
- A try block can have multiple catch blocks.
- The expression after Catch keyword is catch type.
- CLR searches the catch type from top to bottom.

Presenter: Harsh Wardhan, Mindfire Solutions
The Catch
- What to do in a catch block?
– Re-throw same exception.
– Throw a different exception with richer
exception information to code higher up in the
call stack.
– Let the thread fall out of the bottom of the
catch block.

Presenter: Harsh Wardhan, Mindfire Solutions
The Finally
- It contains code that's guranteed to execute.
- Mostly contains clean up operations required by
actions taken in try block.
- Code in catch and finally blocks should be short
and should have likelihood of succeeding without
itself throwing an exception.

Presenter: Harsh Wardhan, Mindfire Solutions
A look into System.Exception
- Base class for all exceptions.
- All user and system defined exceptions derive from
System.Exception class.
- Important Properties of System.Exception:
- Message
- Data
- Source
- Stack-trace
- Target Site
- Help link
- Inner exception
Presenter: Harsh Wardhan, Mindfire Solutions
Throwing Exception
- Points to consider while throwing an exception:
– What exception derived type you need to
throw.
– What string message are you going to pass
to the exception type's constructor.

Presenter: Harsh Wardhan, Mindfire Solutions
Defining your own Exception
class
- Create your exception class when the error is
tightly bound to the class issuing the error.
- Your exception class should be shallow and wide.

Presenter: Harsh Wardhan, Mindfire Solutions
Defining your own Exception
class
- Best practices for creating Exception class:
– Should derive from ApplicationException
– Marked with <System.Seralizable> attribute
– Defines a default constructor
– Defines a constructor that sets inherited
message property.
– Defines a constructor to handle inner exception.
– Defines a constructor for serialization of your
type.
Presenter: Harsh Wardhan, Mindfire Solutions
Best Practices
- Use
–
–
–

finally block liberally.
Use finally to clean up from any operation.
Dispose objects to avoid resource leak.
Examples in our language compiler:
• Lock statement.
• Using statement.
• For each statement.

Presenter: Harsh Wardhan, Mindfire Solutions
Best Practices
- Don't Catch everything.
– When you catch an exception you are
actually saying one of these things:
• You expected this exeption.
• You understand why it occurred.
• You know how to deal with it.

Presenter: Harsh Wardhan, Mindfire Solutions
Best Practices
- NEVER leave an empty catch block.
- Always try to catch specific exceptions.
- Catch a System.Exception and execute some code
inside catch block as long as you re-throw the
exception.

Presenter: Harsh Wardhan, Mindfire Solutions
Unhandled Exceptions
- If no catch block matches the thrown exception
type, an unhandled exception occurs.
- Usually information gets logged in Event Log.

Presenter: Harsh Wardhan, Mindfire Solutions
Debugging Exceptions
- You can enable the exception to break the flow
when it occurs.
- Helps in finding the exceptions being swallowed.
- You can add your own exception.

Presenter: Harsh Wardhan, Mindfire Solutions
Question and
Answer

Presenter: Harsh Wardhan, Mindfire Solutions
Thank you

Presenter: Harsh Wardhan, Mindfire Solutions

More Related Content

What's hot

Exception handler
Exception handler Exception handler
Exception handler dishni
 
Exception handling
Exception handlingException handling
Exception handlingRavi Sharda
 
Exception Handling In Java
Exception Handling In JavaException Handling In Java
Exception Handling In Javaparag
 
C# Exceptions Handling
C# Exceptions Handling C# Exceptions Handling
C# Exceptions Handling sharqiyem
 
Exception handling in java
Exception handling in javaException handling in java
Exception handling in javaPratik Soares
 
Exception handling
Exception handlingException handling
Exception handlingpooja kumari
 
Exception handling in c
Exception handling in cException handling in c
Exception handling in cMemo Yekem
 
7.error management and exception handling
7.error management and exception handling7.error management and exception handling
7.error management and exception handlingDeepak Sharma
 
Exception handling in JAVA
Exception handling in JAVAException handling in JAVA
Exception handling in JAVAKunal Singh
 
14 exception handling
14 exception handling14 exception handling
14 exception handlingjigeno
 
Best Practices in Exception Handling
Best Practices in Exception HandlingBest Practices in Exception Handling
Best Practices in Exception HandlingLemi Orhan Ergin
 
Exception Handling Java
Exception Handling JavaException Handling Java
Exception Handling Javaankitgarg_er
 
Exceptionhandling
ExceptionhandlingExceptionhandling
ExceptionhandlingNuha Noor
 
Java exception handling
Java exception handlingJava exception handling
Java exception handlingBHUVIJAYAVELU
 

What's hot (20)

Exception handler
Exception handler Exception handler
Exception handler
 
Exception handling
Exception handlingException handling
Exception handling
 
Exception Handling In Java
Exception Handling In JavaException Handling In Java
Exception Handling In Java
 
C# Exceptions Handling
C# Exceptions Handling C# Exceptions Handling
C# Exceptions Handling
 
Exception handling in java
Exception handling in javaException handling in java
Exception handling in java
 
Exception handling in java
Exception handling in java Exception handling in java
Exception handling in java
 
Exception handling
Exception handlingException handling
Exception handling
 
Exception handling
Exception handlingException handling
Exception handling
 
Exception handling in c
Exception handling in cException handling in c
Exception handling in c
 
C++ ala
C++ alaC++ ala
C++ ala
 
7.error management and exception handling
7.error management and exception handling7.error management and exception handling
7.error management and exception handling
 
Exception handling in JAVA
Exception handling in JAVAException handling in JAVA
Exception handling in JAVA
 
Exception Handling in Java
Exception Handling in JavaException Handling in Java
Exception Handling in Java
 
14 exception handling
14 exception handling14 exception handling
14 exception handling
 
javaexceptions
javaexceptionsjavaexceptions
javaexceptions
 
Best Practices in Exception Handling
Best Practices in Exception HandlingBest Practices in Exception Handling
Best Practices in Exception Handling
 
Exception Handling Java
Exception Handling JavaException Handling Java
Exception Handling Java
 
Exception handling
Exception handlingException handling
Exception handling
 
Exceptionhandling
ExceptionhandlingExceptionhandling
Exceptionhandling
 
Java exception handling
Java exception handlingJava exception handling
Java exception handling
 

Similar to Understanding Exception Handling in .Net

Similar to Understanding Exception Handling in .Net (20)

Java exeception handling
Java exeception handlingJava exeception handling
Java exeception handling
 
06 exceptions
06 exceptions06 exceptions
06 exceptions
 
Exception hierarchy
Exception hierarchyException hierarchy
Exception hierarchy
 
Exception handling
Exception handlingException handling
Exception handling
 
Exception
ExceptionException
Exception
 
Exception handling
Exception handlingException handling
Exception handling
 
Java: Exception
Java: ExceptionJava: Exception
Java: Exception
 
Exceptionhandling
ExceptionhandlingExceptionhandling
Exceptionhandling
 
Interface andexceptions
Interface andexceptionsInterface andexceptions
Interface andexceptions
 
Exception handling in .net
Exception handling in .netException handling in .net
Exception handling in .net
 
UNIT III 2021R.pptx
UNIT III 2021R.pptxUNIT III 2021R.pptx
UNIT III 2021R.pptx
 
UNIT III 2021R.pptx
UNIT III 2021R.pptxUNIT III 2021R.pptx
UNIT III 2021R.pptx
 
CS3391 -OOP -UNIT – III NOTES FINAL.pdf
CS3391 -OOP -UNIT – III  NOTES FINAL.pdfCS3391 -OOP -UNIT – III  NOTES FINAL.pdf
CS3391 -OOP -UNIT – III NOTES FINAL.pdf
 
DEFCON 21: EDS: Exploitation Detection System WP
DEFCON 21: EDS: Exploitation Detection System WPDEFCON 21: EDS: Exploitation Detection System WP
DEFCON 21: EDS: Exploitation Detection System WP
 
Java Exceptions and Exception Handling
 Java  Exceptions and Exception Handling Java  Exceptions and Exception Handling
Java Exceptions and Exception Handling
 
Lecture 1 Try Throw Catch.pptx
Lecture 1 Try Throw Catch.pptxLecture 1 Try Throw Catch.pptx
Lecture 1 Try Throw Catch.pptx
 
Exceptions overview
Exceptions overviewExceptions overview
Exceptions overview
 
8 Exception Handling
8 Exception Handling8 Exception Handling
8 Exception Handling
 
ETCSS: Into the Mind of a Hacker
ETCSS: Into the Mind of a HackerETCSS: Into the Mind of a Hacker
ETCSS: Into the Mind of a Hacker
 
CLR Exception Handing And Memory Management
CLR Exception Handing And Memory ManagementCLR Exception Handing And Memory Management
CLR Exception Handing And Memory Management
 

More from Mindfire Solutions (20)

Physician Search and Review
Physician Search and ReviewPhysician Search and Review
Physician Search and Review
 
diet management app
diet management appdiet management app
diet management app
 
Business Technology Solution
Business Technology SolutionBusiness Technology Solution
Business Technology Solution
 
Remote Health Monitoring
Remote Health MonitoringRemote Health Monitoring
Remote Health Monitoring
 
Influencer Marketing Solution
Influencer Marketing SolutionInfluencer Marketing Solution
Influencer Marketing Solution
 
ELMAH
ELMAHELMAH
ELMAH
 
High Availability of Azure Applications
High Availability of Azure ApplicationsHigh Availability of Azure Applications
High Availability of Azure Applications
 
IOT Hands On
IOT Hands OnIOT Hands On
IOT Hands On
 
Glimpse of Loops Vs Set
Glimpse of Loops Vs SetGlimpse of Loops Vs Set
Glimpse of Loops Vs Set
 
Oracle Sql Developer-Getting Started
Oracle Sql Developer-Getting StartedOracle Sql Developer-Getting Started
Oracle Sql Developer-Getting Started
 
Adaptive Layout In iOS 8
Adaptive Layout In iOS 8Adaptive Layout In iOS 8
Adaptive Layout In iOS 8
 
Introduction to Auto-layout : iOS/Mac
Introduction to Auto-layout : iOS/MacIntroduction to Auto-layout : iOS/Mac
Introduction to Auto-layout : iOS/Mac
 
LINQPad - utility Tool
LINQPad - utility ToolLINQPad - utility Tool
LINQPad - utility Tool
 
Get started with watch kit development
Get started with watch kit developmentGet started with watch kit development
Get started with watch kit development
 
Swift vs Objective-C
Swift vs Objective-CSwift vs Objective-C
Swift vs Objective-C
 
Material Design in Android
Material Design in AndroidMaterial Design in Android
Material Design in Android
 
Introduction to OData
Introduction to ODataIntroduction to OData
Introduction to OData
 
Ext js Part 2- MVC
Ext js Part 2- MVCExt js Part 2- MVC
Ext js Part 2- MVC
 
ExtJs Basic Part-1
ExtJs Basic Part-1ExtJs Basic Part-1
ExtJs Basic Part-1
 
Spring Security Introduction
Spring Security IntroductionSpring Security Introduction
Spring Security Introduction
 

Recently uploaded

Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfhans926745
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdflior mazor
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?Antenna Manufacturer Coco
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 

Recently uploaded (20)

Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 

Understanding Exception Handling in .Net

  • 1. Understanding Exception Handling in .net. Presenter: Harsh Wardhan, Mindfire Solutions Date: 29/10/2013
  • 2. Agenda - What is Exception? - The try, the catch & the finally. - A look into System.Exception class. - Throwing Exception. - Defining your own exception class. - Best practices. - Unhandled Exceptions. - Debugging Exceptions. Presenter: Harsh Wardhan, Mindfire Solutions
  • 3. What is Exception? - When a member fails to complete the task it is supposed to perform as indicated by its name, it is called an exception. Presenter: Harsh Wardhan, Mindfire Solutions
  • 4. The Try - A Try block contains code that require: - Common clean up operations. - Exception recovery operations. - A code that might potentially throw an exception. - A Try block should have at least one catch or finally block associated with it. - How much code should be added in a single try block? Presenter: Harsh Wardhan, Mindfire Solutions
  • 5. The Catch - Contains code to execute in response to an exception. - A try block can have multiple catch blocks. - The expression after Catch keyword is catch type. - CLR searches the catch type from top to bottom. Presenter: Harsh Wardhan, Mindfire Solutions
  • 6. The Catch - What to do in a catch block? – Re-throw same exception. – Throw a different exception with richer exception information to code higher up in the call stack. – Let the thread fall out of the bottom of the catch block. Presenter: Harsh Wardhan, Mindfire Solutions
  • 7. The Finally - It contains code that's guranteed to execute. - Mostly contains clean up operations required by actions taken in try block. - Code in catch and finally blocks should be short and should have likelihood of succeeding without itself throwing an exception. Presenter: Harsh Wardhan, Mindfire Solutions
  • 8. A look into System.Exception - Base class for all exceptions. - All user and system defined exceptions derive from System.Exception class. - Important Properties of System.Exception: - Message - Data - Source - Stack-trace - Target Site - Help link - Inner exception Presenter: Harsh Wardhan, Mindfire Solutions
  • 9. Throwing Exception - Points to consider while throwing an exception: – What exception derived type you need to throw. – What string message are you going to pass to the exception type's constructor. Presenter: Harsh Wardhan, Mindfire Solutions
  • 10. Defining your own Exception class - Create your exception class when the error is tightly bound to the class issuing the error. - Your exception class should be shallow and wide. Presenter: Harsh Wardhan, Mindfire Solutions
  • 11. Defining your own Exception class - Best practices for creating Exception class: – Should derive from ApplicationException – Marked with <System.Seralizable> attribute – Defines a default constructor – Defines a constructor that sets inherited message property. – Defines a constructor to handle inner exception. – Defines a constructor for serialization of your type. Presenter: Harsh Wardhan, Mindfire Solutions
  • 12. Best Practices - Use – – – finally block liberally. Use finally to clean up from any operation. Dispose objects to avoid resource leak. Examples in our language compiler: • Lock statement. • Using statement. • For each statement. Presenter: Harsh Wardhan, Mindfire Solutions
  • 13. Best Practices - Don't Catch everything. – When you catch an exception you are actually saying one of these things: • You expected this exeption. • You understand why it occurred. • You know how to deal with it. Presenter: Harsh Wardhan, Mindfire Solutions
  • 14. Best Practices - NEVER leave an empty catch block. - Always try to catch specific exceptions. - Catch a System.Exception and execute some code inside catch block as long as you re-throw the exception. Presenter: Harsh Wardhan, Mindfire Solutions
  • 15. Unhandled Exceptions - If no catch block matches the thrown exception type, an unhandled exception occurs. - Usually information gets logged in Event Log. Presenter: Harsh Wardhan, Mindfire Solutions
  • 16. Debugging Exceptions - You can enable the exception to break the flow when it occurs. - Helps in finding the exceptions being swallowed. - You can add your own exception. Presenter: Harsh Wardhan, Mindfire Solutions
  • 17. Question and Answer Presenter: Harsh Wardhan, Mindfire Solutions
  • 18. Thank you Presenter: Harsh Wardhan, Mindfire Solutions