Implicit and explicit sequence control with exception handling


Published on

Focus on Exception handling... in C# with Implicit and Explicit sequence control By Vikash Mainanwal

Published in: Education, Technology
1 Comment
1 Like
No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

Implicit and explicit sequence control with exception handling

  1. 1. A Presentation 0f Advance Pr0gramming Language Implicit & Explicit Sequence Control and Exception Handling Master of Technology In Computer Science &Engineering Submitted T0 Submitted By Miss. Manshi Gupta Vikash MainanwaI
  2. 2. Control Structure Sequence Control Structure Implicit Explicit Exception Exception Handling Bibliography CONTENTS
  3. 3. Control structures: the basic framework within which operations and data are combined into programs.  Sequence control  data control 1.Control Structure
  4. 4. the control of the order of execution of the operations (Primitive, user defined). 1.1 Sequence control 1.2 Data control the control of the transmission of data among the subprograms of a program.
  5. 5. Implicit sequence control: (default) defined by the language . Explicit sequence control: defined by the programmer. Types of sequence control
  6. 6. Example of Explicit Sequence control
  7. 7. Describe Exception An exception is an erroneous situation that occurs during program execution. When an exception occurs in an application, the system throws an error. The error is handled through the process of exception handling.
  8. 8. Types of Error There are three types of errors that can occur in the application: Syntax errors: Occurs when statements are not constructed properly, keywords are misspelled, or punctuation is omitted. Run-time errors: Occurs when an application attempts to perform an operation, which is not allowed at runtime. Logical errors: Occurs when an application compiles and runs properly but does not produce the expected results. Let us understand the various types of errors in detail.
  9. 9. Syntax Error class Errors { Console.WriteLine(“Enjoy Errors”) } Semicolon is missing from Console.WriteLine statement
  10. 10. Run Time Error class Errors { int Num1=0; int Num2=20; int Num3; Num3=Num2/Num1; Console.WriteLine(“The Result is {0}”, Num3); } Division by zero has taken place
  11. 11. Logical Error class Errors { int Num1=10; int Num2=2; int Num3; Num3=Num2/Num1; Console.WriteLine(“The Result is {0}”, Num3); } Expected result = 5 Present result = 0.2
  12. 12. There are many exception classes which are directly or indirectly derived from the System.Exception class. Some of these classes are: System.ApplicationException class System.SystemException class Exception Classes
  13. 13. —The hierarchy of the exception classes is displayed in the following figure. Exception Classes System. Exception System.ApplicationException System.SystemException
  14. 14. Handling Exception In exception handling, the application is divided into blocks of code. A block that shows the probability of raising an error contains one or more exception handlers. The exception handlers follow a control structure and a uniform way of handling the system level and application level errors. The blocks for exception-handling can be implemented using the following keywords: try catch finally Let us look at each of these keywords in detail.
  15. 15. Exception Handling Control Flow
  16. 16. Try Block The try block: The try block guards statements that may throw an exception. Following is the syntax of try block statement: try { //statements that may cause an exception } The try block governs statements that are enclosed within it and defines the scope of the exception-handlers associated with it. A try block must have at least one catch block.
  17. 17. Catch Block The catch block: The catch statement of the catch block takes an object of the exception class as a parameter, which refers to the raised exception. You can associate an exception-handler with the try block by providing one or more catch handlers, immediately after the try block: try { //statements that may cause an exception } catch (…) { //error handling code }
  18. 18. Finally Block The finally block: The finally block is used to execute a given set of statements, whether an exception is thrown or not thrown: try { //statements that may cause an exception } catch (…) { //error handling code } finally { //statements to be executed }
  19. 19. Example of Exception Handling
  20. 20. Bibliography • Programming Language Terrance W.Pratt • — • — us/library/ms173160.aspx  — g. • The complete reference C# 4.0 Tata McGraw-Hill