You are on page 1of 54

EXCEPTIONS AND OBJECT

LIFE TIME
Mr. G.C.Deshpande
Lecturer, CSE@KLS.GIT

Topic Level Objectives


To confabulate about handling runtime anomalies in
the code base through the use of structured
exception handling.
To examine the memory management process
using the .NET garbage collector. To familiarize the
C# keywords such as try, catch, throw and finally.
To examine the distinction between applicationlevel and system-level exceptions.
To inspect various tools within Visual Studio 2012 to
debug the exceptions.
To elucidate the role of application roots, object
generations, and the System.GC type.
To confabulate disposable objects (via the
IDisposable interface) and finalization process (via

Intended Learning Outcomes


1. Investigate various tools within Visual Studio 2012 to debug the exceptions [L 4].
2. Manage the memory using .NET garbage collector [L 3].
3. Clarify the distinction between classes, objects and references [L 2].
4. Explain the role of application roots [L 2].
5. Determine the objects reachable by application roots [L 2].
6. Describe System.GC members and their meaning in life [L 1].
7. Illustrate select members of System.GC type [L 5].
8. Explain the finalization process [L 2].
9. Implement finalizable and disposable objects [L 3].
10. Explain a formalized diaposal pattern [L 2].
11. Define anomaly-centric terms [L 1].
12. Explain the role of .NET exception handling and its atoms [L 2].
13. Explain various properties in configuring the state of an exception [L 2].
14. Differentiate between system level exceptions and application level exceptions [L 4].
15. Build custom/application level exceptions [L 5].
16. Explain the processing of multiple exceptions and the finally block [L 2].
17. Demonstrate the debugging of unhandled exceptions using visual studio 2012 [L 3].

Structured Exception Handling


[SEH]
Bugs: Error made by the programmer
User Errors: Error made by the user
Exceptions: Really exceptional circumstances !!!.. Runtime

anomalies that are difficult to account for while


programming your application.
SEH : Dealing with runtime anomalies.

Role of .NET Exception Handling

Structured Exception Handling


[SEH]
Lot of Numerical codes
Lack of symmetry
SEH : Unified approach to exceptional handling common to

all languages
Human readable description of errors

The Atoms of .NET Exception


Handling

The System.Exception Base Class

The System.Exception Base Class

Core members of
System.Exception type

Core members of
System.Exception type

The simplest possible example

The simplest possible example

The simplest possible example

The simplest possible example

The simplest possible example

Throwing a General Exception

Catching Exceptions

Catching Exceptions

Catching Exceptions

Defining the Pillars of OOP


Encapsulation: How does this language hide an

objects internal implementation details and


preserve data integrity?
Inheritance: How does this language promote
code reuse?
Polymorphism: How does this language let you
treat related objects in a similar way?

Role of Encapsulation

Role of Inheritance [ is-a ]

Role of Inheritance [ has-a ]

Role of Polymorphism

Role of Polymorphism

C# Access Modifiers

C# Access Modifiers

The first pillar: Encapsulation

The first pillar: Encapsulation


Objects internal data should not be directly

accessible from an object instance


Alter the state of an object indirectly using
Accessors (get) and Mutators (set)
.Net property

Black Box Programming

Traditional Encapsulation

Traditional Encapsulation

Encapsulation using Accessors and


Mutators

Encapsulation using Accessors and


Mutators

Encapsulation using .Net


Properties

Encapsulation using .Net


Properties

Encapsulation using .Net


Properties

Encapsulation using .Net


Properties

Controlling Visibility Levels of


Properties

read-only : omit the set block


write-only : omit the get block

Chaining of Constructors

Chaining of Constructors

Basic Mechanics of Inheritance

Basic Mechanics of Inheritance

Basic Mechanics of Inheritance

The sealed keyword

Inheritance

Inheritance

Controlling the base class creation

Controlling the base class creation

Controlling the base class creation


Some properties may be readonly
Inefficient way of creating a constructor: since base class

Default constructor is called before the logic of derived class constructor

Controlling the base class creation

References
1] Andrew Troelsen, Pro C#with.NET 3.0, SpecialEdition,
Dream tech Press, India, 2007.
2]E. Balagurusamy, Programming in C#, 5thReprint, Tata
McGraw Hill,
2004(For Programming Examples).
3] Tom Archer, Inside C#, WP Publishers, 2001.
4]Herbert Schildt,C#: The Complete Reference, TMH,
2004.
5] Yashavant Kanetkar, C#.NET fundas, First Edition, BPB
Publications,
2002

Contact Me
Email: gcdeshpande@git.edu
gcdeshpande@hotmail.com
Blog: gcdeshpande.spaces.live.com
Follow on twitter:
www.twitter.com/gcdeshpande

You might also like