Exception Handling in .NET Framework презентация

Structured Exceptions Handling in .NET
 V'yacheslav Koldovskyy
 SoftServe University
 2014Contents1. Introduction to structured exception handlingMain task – correct operation of the application
 There are possibleObsolete check-based method
 Obsolete error handling method is based on multipleStructured exception handling
 Modern way to handle errors provides using of2. Construct «try..catch»Simplest "try..catch" constuct
       try
 "try..catch" construct with specific exception
      Cascade sections of catch
       try
"try..catch" construct with instance of exception3. «Exception» class and exception hierarchy in.NET FrameworkException class
 Exception is a base class for all exceptions исключений
Exception hierarchy in .NET Framework4. Exception throwing and re-risingException throwingException re-rising5. Creating own exceptionsException declarationMSDN recommendations for exception declarations6. Construct «try..finally»Using finally
 «try..finally» used when it is required to guarantee execution7. Best practices for exception handlingBest practices for exception handling
 Do not catch general exceptions (do8. References to additional sources
 MSDN recommendations for creating exceptions: http://msdn.microsoft.com/en-us/library/ms173163.aspx
Contacts



Слайды и текст этой презентации
Слайд 1
Описание слайда:
Structured Exceptions Handling in .NET V'yacheslav Koldovskyy SoftServe University 2014


Слайд 2
Описание слайда:
Contents

Слайд 3
Описание слайда:
1. Introduction to structured exception handling

Слайд 4
Описание слайда:
Main task – correct operation of the application There are possible situations during the application execution when predetermined plan of actions may be changed Developer should provide ways to ensure correct execution despite possible errors

Слайд 5
Описание слайда:
Obsolete check-based method Obsolete error handling method is based on multiple checks of input data and operation return codes. Drawbacks: difficulties; bloated code; unreliable.

Слайд 6
Описание слайда:
Structured exception handling Modern way to handle errors provides using of special mechanism – structured exception handling which is the part of programming language Exception is an event which happens during software execution and changes normal way of code execution Exceptions in .NET Framework are instances of classes inherited from base class Exception. Only instances of this class and inherited classes may participated in structured exception handling.

Слайд 7
Описание слайда:
2. Construct «try..catch»

Слайд 8
Описание слайда:
Simplest "try..catch" constuct try { // Code which may result in exception } catch { // Code executed only in case of exception }

Слайд 9
Описание слайда:
"try..catch" construct with specific exception try { // Code which may result in exception } catch (DivideByZeroException) { // Code executed in case of exception }

Слайд 10
Описание слайда:
Cascade sections of catch try { // Code which may result in exception catch (DivideByZeroException) { // Code executed in case of exception type DivideByZeroException } catch (Exception) { // Code executed in case of exception type Exception // Means "any exception" }

Слайд 11
Описание слайда:
"try..catch" construct with instance of exception

Слайд 12
Описание слайда:
3. «Exception» class and exception hierarchy in.NET Framework

Слайд 13
Описание слайда:
Exception class Exception is a base class for all exceptions исключений Important properties: Message – user-oriented message about error Source – name of an error source (application or object) InnerException – inner exception (if called from other) StackTrace – call stack to the point of exception call TargetSite – method name which raised an exception HelpLink – URL-address to information about exception Data – dictionary with additional information with exception (IDictionary)

Слайд 14
Описание слайда:
Exception hierarchy in .NET Framework

Слайд 15
Описание слайда:
4. Exception throwing and re-rising

Слайд 16
Описание слайда:
Exception throwing

Слайд 17
Описание слайда:
Exception re-rising

Слайд 18
Описание слайда:
5. Creating own exceptions

Слайд 19
Описание слайда:
Exception declaration

Слайд 20
Описание слайда:
MSDN recommendations for exception declarations

Слайд 21
Описание слайда:
6. Construct «try..finally»

Слайд 22
Описание слайда:
Using finally «try..finally» used when it is required to guarantee execution of some code May be used together with catch

Слайд 23
Описание слайда:
7. Best practices for exception handling

Слайд 24
Описание слайда:
Best practices for exception handling Do not catch general exceptions (do not use catch without parameters or catch(Exception) ) Create own exceptions based on ApplicationException class but not on SystemException Do not use exceptions for application execution control flow as exception handling is heavy resource usage task. Exceptions should be used to manage errors only Do not mute exceptions which can’t be handled in application context (system errors and failures). Do not raise general exceptions: Exception, SystemException, ApplicationException Do not generate reserved system exceptions: ExecutionEngineException, IndexOutOfRangeException, NullReferenceException, OutOfMemoryException Do not return an exception instance as a method return result instead of using throw. Do not create exceptions used only for debugging purposes. Do define debug-only exceptions use Assert.

Слайд 25
Описание слайда:
8. References to additional sources MSDN recommendations for creating exceptions: http://msdn.microsoft.com/en-us/library/ms173163.aspx MSDN recommendation for exception generation: http://msdn.microsoft.com/en-us/library/ms182338.aspx Full hierarchy of Microsoft .NET Framework exceptions (code sample in comments): http://stackoverflow.com/questions/2085460/c-sharp-is-there-an-exception-overview

Слайд 26
Описание слайда:
Contacts


Скачать презентацию на тему Exception Handling in .NET Framework можно ниже:

Похожие презентации