Partnership.

Slides:



Advertisements
Similar presentations
Exceptions1 Syntax, semantics, and pragmatics. Exceptions2 Syntax, semantics, pragmatics Syntax –How it looks, i.e. how we have to program to satisfy.
Advertisements

CONTENTS:-  What is Event Log Service ?  Types of event logs and their purpose.  How and when the Event Log is useful?  What is Event Viewer?  Briefing.
UNIT-V The MVC architecture and Struts Framework.
B USINESS LAYER SAMANVITHA RAMAYANAM 4 th MARCH 2010 CPE 691.
Introduction to the Enterprise Library. Sounds familiar? Writing a component to encapsulate data access Building a component that allows you to log errors.
And other languages…. must remember to check return value OR, must pass label/exception handler to every function Caller Function return status Caller.
Lecture 8 Inheritance Richard Gesick. 2 OBJECTIVES How inheritance promotes software reusability. The concepts of base classes and derived classes. To.
SWE 316: Software Design and Architecture – Dr. Khalid Aljasser Objectives Lecture 11 : Frameworks SWE 316: Software Design and Architecture  To understand.
Exceptions1 Syntax, semantics, and pragmatics. Exception create If (some error){ throw new SomeException(”some message”); } Exceptions2.
CS 390- Unix Programming Environment CS 390 Unix Programming Environment Topics to be covered: Distributed Computing Fundamentals.
07 Coding Conventions. 2 Demonstrate Developing Local Variables Describe Separating Public and Private Members during Declaration Explore Using System.exit.
Exceptions Syntax, semantics, and pragmatics Exceptions1.
Introduction to Exception Handling and Defensive Programming.
Ready Marjan Nikolovski Father, Dev, CEO/Emit Knowledge Down the rabbit hole Error handling examined try { } // // Blog: emitknowledge.com/research-labs.
Distribution and components. 2 What is the problem? Enterprise computing is Large scale & complex: It supports large scale and complex organisations Spanning.
Design Patterns -- Omkar. Introduction  When do we use design patterns  Uses of design patterns  Classification of design patterns  Creational design.
Vinay Paul. CONTENTS:- What is Event Log Service ? Types of event logs and their purpose. How and when the Event Log is useful? What is Event Viewer?
Introduction to Object-Oriented Programming Lesson 2.
Exception Handling in Java Topics: Introduction Errors and Error handling Exceptions Types of Exceptions Coding Exceptions Summary.
Data Design and Implementation. Definitions Atomic or primitive type A data type whose elements are single, non-decomposable data items Composite type.
Enterprise Library Caching Application Block Peter Provost Software Design Engineer Ron Jacobs Product Manager Scott Densmore Software Design Engineer.
Exceptions in OO Programming Introduction Errors Exceptions in Java Handling exceptions The Try-Catch-Finally mechanism Example code Exception propagation.
1 Handling Errors and Exceptions Chapter 6. 2 Objectives You will be able to: 1. Use the try, catch, and finally statements to handle exceptions. 2. Raise.
OOP Tirgul 7. What We’ll Be Seeing Today  Packages  Exceptions  Ex4 2.
Enterprise Library 3.0 Memi Lavi Solution Architect Microsoft Consulting Services Guy Burstein Senior Consultant Advantech – Microsoft Division.
Windows Communication Foundation and Web Services
Eighth Lecture Exception Handling in Java
COTS testing Torbjørn Skramstad.
Facade Pattern Jim Fawcett CSE776 – Design Patterns Summer 2010
ATS Application Programming: Java Programming
SOFTWARE TESTING Date: 29-Dec-2016 By: Ram Karthick.
Exceptions David Rabinowitz.
similar concepts, different syntax
Inheritance and Polymorphism
Java Programming Language
Coding Defensively Coding Defensively
Distribution and components
Syntax, semantics, and pragmatics
Magento Technical Guidelines Eugene Shakhsuvarov, Software Magento
Lecture 2 of Computer Science II
Facade Pattern Jim Fawcett CSE776 – Design Patterns Summer 2010
Exception Handling.
COTS testing Tor Stålhane.
YG - CS170.
Lecture 23 Polymorphism Richard Gesick.
Advanced Programming Behnam Hatami Fall 2017.
CNS 3260 C# .NET Software Development
AVG 24th 2015 ADVANCED c# - part 1.
Exceptions Handling the unexpected
On transactions, and Atomic Operations
Exceptions & Error Handling
Lecture 22 Inheritance Richard Gesick.
Improving the structure of existing code
Part B – Structured Exception Handling
On transactions, and Atomic Operations
An Introduction to Software Architecture
Exception Handling.
Programming in C# Lesson 5. Exceptions..
Exception Handling Imran Rashid CTO at ManiWeber Technologies.
SAMANVITHA RAMAYANAM 18TH FEBRUARY 2010 CPE 691
Error Handling.
Applying Use Cases (Chapters 25,26)
Applying Use Cases (Chapters 25,26)
System Reengineering Restructuring or rewriting part or all of a system without changing its functionality Applicable when some (but not all) subsystems.
CMSC 202 Exceptions.
Exception Handling.
Exceptions.
C++ Object Oriented 1.
Exceptions and networking
Presentation transcript:

Partnership

Exception handling guidelines Basic ex. handling patterns Guidelines and best practices Anti-patterns, or not ?! Exception handling application block

Introduction Why should we think about the exception handling and the logging? Software maintenance (Administrators, technical support) Uniform and clean code Prevents application of having large amount of unexpected and confusing behavior

Exception handling patterns Exception shielding Protects sensitive information and prevents their leaking Exception translating Wraps original exception with purpose to add some extra info, or to adapt exception to the layer above. Example: Used by Hibernate API (doesn’t throw the SQLException, hides sensitive information) Exception logging Leaves useful information about the exception which occurred

The typical exception handling actions Handle it (perform retry or an additional action) Propagate it (re-throw it) Wrap it and throw a new exception Log it (Do not use Console.WriteLine or System.out to log the data) Mix of previously mentioned approaches

1. Make ex. handling plan in development phase Define exception handling policy for the software architecture: Consider and divide critical parts of the architecture from non critical Put security barriers in the architecture Cover all application threads with safety nets

2. Avoid leaving an empty exception handler Can hide crucial parts of scenario which caused issue Problem diagnosis can be extremely hard (sometimes only debug procedure through tool is only option)

3. Provide as much as possible of exception data Exception message Exception stack trace Exception code (if available) Custom (additional) properties All inner exceptions

4. Take security into consideration Hide sensitive details and information: Database type or provider Server info

5. Put a human readable message in the exception log Helps technical support and administrators. Makes the log file more readable and understandable. Sometimes, raw exception message can be very confusing without some vital information for debug process.

6. Use built-in exceptions if applicable Before you create a new exception class, check whether some system exception can be used. ArgumentException ArgumentNullException InvalidCastException InvalidOperationException System.IO.FileNotFoundException System.IO.PathTooLongException Etc..

7. Create new exceptions by following a platform guidelines All recommended constructors should be supported Make an exception serializable(if necessary) Follow naming convention for the exception class If you chose to override built-in exception follow the same guidelines

8. Avoid resetting stack trace Do not use ‘throw ex;’ to propagate further exception, use ‘throw;’ instead. ‘throw ex’ statement resets stack trace to the point of the current line execution, therefore original exception source is hidden.

9. Study the exception handling policy of the API you use It’s essential to build exception handling logic above it. It’s possible that you will find unexpected behavior which requires special treatment. WCF client dispose method throws additional exception when connection is in the fault state, hiding the real exception cause that way.

10. Handle a specific exception close to the place of its cause All relevant variables and resources are available, therefore the most appropriate ex. handling action can be invoked, either to sanitize exception, retry an action or simply log error data. Human readable (useful) log message can be made with all necessary data. Avoid using general exception handlers for handling specific errors.

Anti-patterns, or not ? Approach log and throw ?! Handler catch (Exception ex) ?! – fine for safety net, wrong for handling specific exceptions Catch and return null – definitely a bad practice (can introduce lots of confusion) Throw from finally – hides real exception (similar to the WCF client dispose issue) Return default value for unimplemented operations in the interface - throw NotImplementedException instead Singleton implementation by the static constructor ?! Ensuring a synchronous approach to the singleton by using a queue execution

Enterprise library - EHAB The Microsoft Enterprise library is a collection of reusable software components called: application blocks, designed to assist developers with common enterprise development concerns (MSDN). Exception handling Application block (EHAB) is designed to centralize exception handling code, make it configurable and helps us to design uniform and easy to change exception handling infrastructure.

EHAB– Main Concepts ExceptionManager – Main entry point for the exception handling functionality. ExceptionPolicyDefinition – Encapsulates one set of rules for handling exceptions. ExceptionPolicyEntry – Defines rule how to handle one specific exception type. IExceptionHandler – Defines contract (interface) for an ExceptionHandler. An ExceptionHandler contains specific handling logic.

EHAB - Initialization Define an exception policy by specifying appropriate policy definitions and supply it to the exception manager. Post handling actions: None – Nothing is propagated further when all exception handlers in the policy chain are done NotifyRethrow – Original exception is propagated further when all exception handlers in the policy chain are done ThrowNewException – Throws new exception, returned by the last exception handler in the chain, to upper level when all exception handlers in the policy chain are done

EHAB – default handlers WrapHandler - Wraps the current exception with a new exception of a specified type. ReplaceHandler - Replaces the exception with an entirely new exception. LoggingExceptionHandler -  formats the exception into a log message and writes it down in appropriate location.

EHAB - Usage Use either Process or HandleException method of the ExceptionManager class. Process method is used to entirely replace try – catch block but it can be used in combination with it. HandleException method is used always in combination with try – catch block and it’s called to handle a specific exception by specified policy (Gives directly a result of the exception handling policy). Use HandlingInstanceId to give a single piece of information to the user which can be used to obtain specific details of exception

EHAB - DEMO In demo simple user management application will be used. Contains DAL (data access layer) layer Has simple UI interface Has exception policy defined in the ApplicationManager singleton

References http://www.vegaitsourcing.rs/#!/articles/2014/1 0/exception-handling http://www.codeproject.com/Articles/9538/Exce ption-Handling-Best-Practices-in-NET http://msdn.microsoft.com/en- us/library/dn440728(v=pandp.60).aspx https://today.java.net/article/2006/04/04/excep tion-handling-antipatterns

Conclusion Always think of the exception handling and logging in design time Follow best practice for the exception handling and try to avoid anti-patterns Use the EHAB or any similar application block to have the exception handling logic centralized, uniform and easy to maintain/change

Thank you