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

Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersRaghuram Pandurangan
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESmohitsingh558521
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxBkGupta21
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 

Recently uploaded (20)

Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information Developers
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptx
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 

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