06cs761 ppts chapter v

54
EXCEPTIONS AND OBJECT LIFE TIME Mr. G.C.Deshpande Lecturer, [email protected]

Upload: gajendra-deshpande

Post on 14-Dec-2015

217 views

Category:

Documents


2 download

DESCRIPTION

C# Programming and .Net Unit 5

TRANSCRIPT

Page 1: 06CS761 PPTs Chapter V

EXCEPTIONS AND OBJECT LIFE TIMEMr. G.C.Deshpande

Lecturer, [email protected]

Page 2: 06CS761 PPTs Chapter V

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 application-level 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 the System.Object.Finalize() method).

Page 3: 06CS761 PPTs Chapter V

Intended Learning Outcomes1. 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].

Page 4: 06CS761 PPTs Chapter V

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.

Page 5: 06CS761 PPTs Chapter V

Role of .NET Exception Handling

Page 6: 06CS761 PPTs Chapter V

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

Page 7: 06CS761 PPTs Chapter V

The Atoms of .NET Exception Handling

Page 8: 06CS761 PPTs Chapter V

The System.Exception Base Class

Page 9: 06CS761 PPTs Chapter V

The System.Exception Base Class

Page 10: 06CS761 PPTs Chapter V

Core members of System.Exception type

Page 11: 06CS761 PPTs Chapter V

Core members of System.Exception type

Page 12: 06CS761 PPTs Chapter V

The simplest possible example

Page 13: 06CS761 PPTs Chapter V

The simplest possible example

Page 14: 06CS761 PPTs Chapter V

The simplest possible example

Page 15: 06CS761 PPTs Chapter V

The simplest possible example

Page 16: 06CS761 PPTs Chapter V

The simplest possible example

Page 17: 06CS761 PPTs Chapter V

Throwing a General Exception

Page 18: 06CS761 PPTs Chapter V

Catching Exceptions

Page 19: 06CS761 PPTs Chapter V

Catching Exceptions

Page 20: 06CS761 PPTs Chapter V

Catching Exceptions

Page 21: 06CS761 PPTs Chapter V

Defining the Pillars of OOPEncapsulation: How does this language hide an object’s 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?

Page 22: 06CS761 PPTs Chapter V

Role of Encapsulation

Page 23: 06CS761 PPTs Chapter V

Role of Inheritance [ is-a ]

Page 24: 06CS761 PPTs Chapter V

Role of Inheritance [ has-a ]

Page 25: 06CS761 PPTs Chapter V

Role of Polymorphism

Page 26: 06CS761 PPTs Chapter V

Role of Polymorphism

Page 27: 06CS761 PPTs Chapter V

C# Access Modifiers

Page 28: 06CS761 PPTs Chapter V

C# Access Modifiers

Page 29: 06CS761 PPTs Chapter V

The first pillar: Encapsulation

Page 30: 06CS761 PPTs Chapter V

The first pillar: Encapsulation

Object’s internal data should not be directly accessible from an object instanceAlter the state of an object indirectly using

Accessors (get) and Mutators (set) .Net property

Black Box Programming

Page 31: 06CS761 PPTs Chapter V

Traditional Encapsulation

Page 32: 06CS761 PPTs Chapter V

Traditional Encapsulation

Page 33: 06CS761 PPTs Chapter V

Encapsulation using Accessors and Mutators

Page 34: 06CS761 PPTs Chapter V

Encapsulation using Accessors and Mutators

Page 35: 06CS761 PPTs Chapter V

Encapsulation using .Net Properties

Page 36: 06CS761 PPTs Chapter V

Encapsulation using .Net Properties

Page 37: 06CS761 PPTs Chapter V

Encapsulation using .Net Properties

Page 38: 06CS761 PPTs Chapter V

Encapsulation using .Net Properties

Page 39: 06CS761 PPTs Chapter V

Controlling Visibility Levels of Properties

read-only : omit the set blockwrite-only : omit the get block

Page 40: 06CS761 PPTs Chapter V

Chaining of Constructors

Page 41: 06CS761 PPTs Chapter V

Chaining of Constructors

Page 42: 06CS761 PPTs Chapter V

Basic Mechanics of Inheritance

Page 43: 06CS761 PPTs Chapter V

Basic Mechanics of Inheritance

Page 44: 06CS761 PPTs Chapter V

Basic Mechanics of Inheritance

Page 45: 06CS761 PPTs Chapter V

The sealed keyword

Page 46: 06CS761 PPTs Chapter V

Inheritance

Page 47: 06CS761 PPTs Chapter V

Inheritance

Page 48: 06CS761 PPTs Chapter V

Controlling the base class creation

Page 49: 06CS761 PPTs Chapter V

Controlling the base class creation

Page 50: 06CS761 PPTs Chapter V

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

Page 51: 06CS761 PPTs Chapter V

Controlling the base class creation

Page 52: 06CS761 PPTs Chapter V

References

1] Andrew Troelsen, Pro C# with .NET 3.0, Special Edition,

Dream tech Press, India, 2007.

2] E. Balagurusamy, Programming in C#, 5th Reprint, 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

 

Page 53: 06CS761 PPTs Chapter V

Contact Me

Email: [email protected]

[email protected]

Blog: gcdeshpande.spaces.live.com

Follow on twitter: www.twitter.com/gcdeshpande

Page 54: 06CS761 PPTs Chapter V