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
Control Structure
Sequence Control Structure
Implicit
Explicit
Exception
Exception Handling
Bibliography
CONTENTS
Control structures: the basic framework
within which operations and data are
combined into programs.
 Sequence control
 data control
1.Control Structure
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.
Implicit sequence control: (default)
defined by the language .
Explicit sequence control: defined by the
programmer.
Types of sequence control
Example of Explicit Sequence control
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.
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.
Syntax Error
class Errors
{
Console.WriteLine(“Enjoy Errors”)
}
Semicolon is missing from Console.WriteLine statement
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
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
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
—The hierarchy of the exception classes is displayed in the following
figure.
Exception Classes
System. Exception
System.ApplicationException
System.SystemException
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.
Exception Handling Control Flow
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.
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
}
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
}
Example of Exception Handling
Bibliography
• Programming Language Terrance W.Pratt
• —www.dotnetperls.com/exception
• —msdn.microsoft.com/en-
us/library/ms173160.aspx
 —www.tutorialspoint.com/csharp/csharp_exception_handlin
g.
• The complete reference C# 4.0 Tata McGraw-Hill
Implicit and explicit sequence control with exception handling
Implicit and explicit sequence control with exception handling

Implicit and explicit sequence control with exception handling

  • 1.
    A Presentation 0fAdvance 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.
    Control Structure Sequence ControlStructure Implicit Explicit Exception Exception Handling Bibliography CONTENTS
  • 3.
    Control structures: thebasic framework within which operations and data are combined into programs.  Sequence control  data control 1.Control Structure
  • 4.
    the control ofthe 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.
    Implicit sequence control:(default) defined by the language . Explicit sequence control: defined by the programmer. Types of sequence control
  • 6.
    Example of ExplicitSequence control
  • 7.
    Describe Exception An exceptionis 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.
    Types of Error Thereare 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.
    Syntax Error class Errors { Console.WriteLine(“EnjoyErrors”) } Semicolon is missing from Console.WriteLine statement
  • 10.
    Run Time Error classErrors { 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.
    Logical Error class Errors { intNum1=10; int Num2=2; int Num3; Num3=Num2/Num1; Console.WriteLine(“The Result is {0}”, Num3); } Expected result = 5 Present result = 0.2
  • 12.
    There are manyexception 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.
    —The hierarchy ofthe exception classes is displayed in the following figure. Exception Classes System. Exception System.ApplicationException System.SystemException
  • 14.
    Handling Exception In exceptionhandling, 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.
  • 16.
    Try Block The tryblock: 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.
    Catch Block The catchblock: 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.
    Finally Block The finallyblock: 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.
  • 20.
    Bibliography • Programming LanguageTerrance W.Pratt • —www.dotnetperls.com/exception • —msdn.microsoft.com/en- us/library/ms173160.aspx  —www.tutorialspoint.com/csharp/csharp_exception_handlin g. • The complete reference C# 4.0 Tata McGraw-Hill