• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Understanding Exception Handling in .Net
 

Understanding Exception Handling in .Net

on

  • 373 views

This seminar will make you familiar with the exception handling concepts in .Net. Anyone who has been working on any of the .net languages or has just started can join in to learn more here.

This seminar will make you familiar with the exception handling concepts in .Net. Anyone who has been working on any of the .net languages or has just started can join in to learn more here.

Statistics

Views

Total Views
373
Views on SlideShare
373
Embed Views
0

Actions

Likes
0
Downloads
9
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Understanding Exception Handling in .Net Understanding Exception Handling in .Net Presentation Transcript

    • 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