12/14/2016. Errors. Debugging and Error Handling. Run-Time Errors. Debugging in C# Debugging in C# (continued)

Size: px
Start display at page:

Download "12/14/2016. Errors. Debugging and Error Handling. Run-Time Errors. Debugging in C# Debugging in C# (continued)"

Transcription

1 Debugging and Error Handling Debugging methods available in the ID Error-handling techniques available in C# Errors Visual Studio IDE reports errors as soon as it is able to detect a problem Error message Syntax errors does not always Language rule violation state the correct problem Quick info Syntax error extraneous semicolon Run-Time Errors Just because your program reports no syntax errors does not necessarily mean it is running correctly One form of run-time error is a logic error Program runs, but produces incorrect results May be off-by-one in a loop Sometime users enter incorrect values Finding the problem can be challenging Debugging in C# Desk check Many IDEs have Debuggers Debuggers let you observer the run-time behavior You can break or halt execution You can step through the application You can evaluate variables You can set breakpoints Debug menu offers debugging options Debugging in C# (continued) Debugging in C# (continued) Select Start Debugging and number of options to run your program doubles Debug menu options Debug menu options during debugging mode 1

2 Breakpoints Markers placed in an application, indicating the program should halt execution when it reaches that point Break mode Examine expressions Check intermediate results Use Debug menu to set Breakpoint F9 (shortcut) Toggles Breakpoints (continued) Red glyph placed on the breakpoint line Breakpoint set Break Mode Break Mode (continued) In Break mode, Debugger displays Locals window All variables and their values are shown Locals window at the breakpoint Breakpoint location Debugging in C# Continue Takes the program out of break mode and restores it to a run-time mode If more than one breakpoint set, Continue causes the program to execute from the halted line until it reaches the next breakpoint Stepping through code Execute code line by line and see the execution path Examine variable and expression values as they change Stepping Through Code Step Into (F11) Program halts at the first line of code inside the called method Step Over (F10) Executes the entire method called before it halts Step Out (Shift+F11) Causes the rest of the program statements in the method to be executed and then control returns to the method that made the call 2

3 Watches Can set Watch windows during debugging sessions Watch window lets you type in one or more variables or expressions to observe while the program is running Watch window differs from Locals window, which shows all variables currently in scope Quick Watch option on Debug menu lets you type a single variable or expression Watches (continued) QuickWatch window Bugs, Errors, and Exceptions Bugs, Errors, and Exceptions (continued) Bugs differ from exceptions Bugs, also called "programmer mistakes," should be caught and fixed before application released Errors can be created because of user actions Example Entering wrong type of data produces unhandled exception when ParseInt( ) called Details button in Visual Studio lists a stack trace of methods with the method that raised the exception listed first Stack trace Figure Unhandled exception raised by incorrect input string Exception-Handling Techniques If event creates a problem frequently, best to use conditional expressions to catch and fix problem Execution is slowed down when CLR has to halt a method and find an appropriate event handler Exception-handling techniques are for serious errors that occur infrequently Exceptions classes integrated within the FCL Used with the try catch finally program constructs What is an exception error? An exception is a problem that arises during the execution of a program. A C# exception is a response to an exceptional situation that arises while a program is running, such as an attempt to divide by zero. 18 3

4 What is an exception error? Exception handling Exceptions provide a way to transfer control from one part of a program to another. C# exception handling is built upon four keywords: try: A try block identifies a block of code for which particular exceptions will be activated. It's followed by one or more catch blocks. catch: A program catches an exception with an exception handler at the place in a program where you want to handle the problem. The catch keyword indicates the catching of an exception Exception handling C# exception handling is built upon four keywords: finally: The finally block is used to execute a given set of statements, whether an exception is thrown or not thrown. For example, if you open a file, it must be closed whether an exception is raised or not. throw: A program throws an exception when a problem shows up. This is done using a throw keyword. DEBUGGING IN VS AND VCE Both VS and VCE(express) allow you to build applications in two configurations: Debug (the default) and Release. 21 DEBUGGING IN VS AND VCE In debug configuration and execute it in debug mode, more is going on than the execution of your code. Debug builds maintain symbolic information about your application, so that the IDE knows exactly what is happening as each line of code is executed In release configuration, application code is optimized. However, release builds also run faster; and when you have finished developing an application, you will typically supply users with release builds because they won t require the symbolic information thatdebug builds include Debug Menu and Toolbar Breakpoints 4

5 Breakpoints Breakpoints Debugging in Break Mode Breakpoints Toggle Breakpoints On/Off by clicking in Editor's gray left margin indicator Monitoring Variable Content Monitoring variable content is just one example of how VS and VCE help you a great deal by simplifying things. The easiest way to check the value of a variable is to hover the mouse over its name in the source code while in break mode. A yellow tooltip showing information about the variable appears, including the variable s current value. Viewing Current Values During Program Execution Place mouse pointer over variable or property to view current value Monitoring Variable Content Autos (VS only): Variables in use in the current and previous statements (Ctrl+D, A) Locals: All variables in scope (Ctrl+D, L) Watch N: Customizable variable and expression display (where N is 1 to 4, found on Debug WindowsWatch) Immediate and CommandWindows The Command (VS only) and Immediate windows (found on the DebugWindows menu) enable you to execute commands while an application is running. The Command window enables you to perform VS operations manually (such as menu and toolbar operations). The Immediate window enables youto execute additional code besides the source code lines being executed, and to evaluate expressions. 5

6 Immediate and CommandWindows Debugging and Error Handling Error-handling available in C# techniques UNDERSTANDING EXCEPTIONS STEP BY STEP 3_1 An exception occurs when a program encounters any unexpected problems. Your program should be able to handle these exceptional situations and, if possible, gracefully recover from them. This is called exception handling. STEP BY STEP 3_1 UNDERSTANDING EXCEPTIONS The FCL provides two categories of exceptions ApplicationException Represents exceptions thrown by the applications SystemException Represents exceptions thrown by the CLR 6

7 try block A try block contains code that requires common cleanup or exception-recovery operations. The cleanup code should be put in a single finally block. The exception recovery code should be put in one or more catch blocks. Create one catch block for each kind of type you want to handle. A try block must have at least one catch or finally block. catch block A catch block contains code to execute in response to an exception. If the code in a try block doesn t cause an exception to be thrown, the CLR will never execute the code in any of its catch blocks. You may or may not specify a catch type in parantheses after catch : The catch type must be of type System.Exception or a type that derived from System.Exception If there is no catch type specified, that catch block handles any exception. This is equivalent to having a catch block that specifies System.Exception as a catch type. CLR searches for a matching catch type from top to bottom. If CLR cannot find any catch type that matches the exception, CLR continues searching up the callstack to find a catch type. catch block Once the catch block that matches the exception is found, you have 3 choices: 1. Re-throw the same exception, notifying the higher-up call stack ofthe exception 2. Throw a different exception, giving richer exception information to code higher-up in the call stack 3. Let the code continue from the bottom of the catch block In choices 1-2, an exception is thrown and code starts looking for a catch block whose type matches the exception thrown In choice 3, the finally block is executed You can also specify a variable name like catch(exception e) to access information specific to the exception. finally block The CLR does not completely eliminate memory leaks. Why? Even though GC does automatic memory clean-up, it only cleans up if there are no references kept on the object. Even then there may be a delay until the memory is required. Thus, memory leaks can occur if programmers inadvertently keep references to unwanted objects. C# provides the finally block, which is guaranteed to execute regardless of whether an exception occurs. If the try block executes without throwing, the finally block executes. If the try block throws an exception, the finally block still executes regardless of whether the exception is caught. This makes the finally block ideal to release resources from the corresponding try block. finally block Local variables in a try block cannot be accessed in the corresponding finally block, so variables that must be accessed in both should be declared before the try block. Placing the finally block before a catch block is a syntax error. A try block does not require a finally block, sometimes no clean-up is needed. A try block can have no more than one finally block. Avoid putting code that might throw in a finally block. Exception handling will still work but the CLR will not keep the information about the first exception just thrown in the corresponding try block. Try Block - General Form The try Block try statements that may cause error catch [ExceptionType VariableName ] statements for action when an exception occurs 7

8 HANDLING EXCEPTIONS The catch Block HANDLING EXCEPTIONS DivideByZeroException ArithmeticException FormatException OverflowException HANDLING EXCEPTIONS HANDLING EXCEPTIONS The throw Statement The throw Statement The throw Statement 8

9 HANDLING EXCEPTIONS The finally Block: contains code that always executes, whether or not any exception occurs. Example 1 1. class Program 2. public static void division(int num1, int num2) float result=0.0f; 5. try result = num1 / num2; catch (DivideByZeroException e) Console.WriteLine("Exception Error!! \n divid by zero!!"); 12. // Console.WriteLine("Exception caught: 0", e); finally Console.WriteLine("Result: 0 ", result); static void Main(string[] args) division(10,0); 22. Console.ReadLine(); Example 2 Practice 1. catch (DivideByZeroException ex2) 2. Try ex1.message 3. // catch (FormatException ex1) // 8. Try Exception only Instead of DivideByZeroException Or FormatException 51 Use IndexOutOfRangeException & FormatException & Exception 52 VALIDATING USER INPUT The Validating Event Field-Level Validation 1. Enter (Occurs when a control is entered.) 2. GotFocus (Occurs when a control receives focus.) 3. Leave (Occurs when focus leaves a control.) 4. Validating (Occurs when a control is validating.) 5. Validated (Occurs when a control is finished validating.) 6. LostFocus (Occurs when a control looses focus.) Inside the Validating event, you can write code to do the following: Programmatically correct any errors or omissions made by the user. Show error messages and alerts to the user so that the user can fix the problem Use the Focus() method of the control to transfer the focus back to the field. Set the Cancel property of CancelEventArgs to true. This cancels the Validating event, leaving the focus in the control. 9

10 VALIDATING USER INPUT 1. KeyDown 2. KeyPress 3. KeyUp The KeyPress event happens after the KeyDown event but before the KeyUp event KeyPress event match keys include any alphabetic and numeric characters (alphanumeric a z, A Z, and 0 9), not raise this event include Ctrl, Alt, and the function keys VALIDATING USER INPUT EXAM private void textboxage_keypress(object sender, KeyPressEventArgs e) if ((e.keychar < 48 e.keychar > 57) && e.keychar!= 8) e.handled = true; private void textbox1_keyup(object sender, System.Windows.Forms.KeyEventArgs e) if (e.alt == true) MessageBox.Show("The ALT key is still down"); Methods Math Class Methods The Math class Allows the user to perform common math calculations Using methods ClassName.MethodName( arument2, ) Constants Math.PI = Math.E = argument1, Method Definitions Writing a custom method Header ReturnType Properties Name( Param1, Param2, ) Body Contains the code of what the method does Contains the return value if necessary For uses call elsewhere in program Pass parameters if needed All methods must be defined inside of a class Method Definitions public void MethodName ( ) // Contains the code of what the method does public ReturnType methodname(param1, Param2, ) //Contains the code of what the method does //Contains the return value 10

11 User-defined method Maximum User-defined method Maximum public double Maximum( double x, double y, double z ) double maximumvalue = x; if ( y > maximumvalue ) maximumvalue = y; if ( z > maximumvalue ) maximumvalue = z; return maximumvalue; // end method Maximum public void DetermineMaximum() Console.WriteLine( "Enter three floating-point values,\n" + " pressing 'Enter' after each one: " ); double number1 = Convert.ToDouble( Console.ReadLine() ); double number2 = Convert.ToDouble( Console.ReadLine() ); double number3 = Convert.ToDouble( Console.ReadLine() ); double result = Maximum( number1, number2, number3 ); Console.WriteLine( "Maximum is: " + result ); Argument Promotion Argument Promotion Implicit Conversion Object is converted to a needed type implicitly Only done if complier knows no data will be lost Explicit Conversion Object is manually converted Required if there could be a loss of data Widening Make an object that of a derived class and more complex Narrowing Make an object that of a base class and cause some data loss Type bool byte sbyte char decimal double float int uint long ulong object short ushort Can be Converted to Type(s) object decimal, double, float, int, uint, long, ulong, object, short or ushort decimal, double, float, int, long, object or short decimal, double, float, int, uint, long, ulong, object or ushort object object double or object decimal, double, float, long or object decimal, double, float, long, ulong, or object decimal, double, float or object decimal, double, float or object None decimal, double, float, int, long or object decimal, double, float, int, uint, long, ulong or object Passing Arguments: Call-By- Value vs. Call-By-Reference Passing by value Send a method a copy of the object When returned are always returned by value Set by value by default Passing by reference Send a method the actual reference point Causes the variable to be changed throughout the program When returned are always returned by reference The ref keyword specifies by reference The out keyword means a called method will initialize it Reference and value parameters void Square( int x ) x = x * x; int z=5; Value of z after Square: 5 Square ( z ); void SquareRef( ref int x int ) z=5; Value of z after SquareRef: 25 x = x * x; SquareRef (ref z ); void SquareOut( out int x ) x=5; x = x * x; int z; Value of z after SquareOut: 25 SquareOut (out z ); 11

12 Random Number Generation Class Random Within namespace System randomobject.next() Returns a number from 0 to Int32.MaxValue Int32.MaxValue = 2,147,483,647 randomobject.next ( x ) Returns a value from 0 up to but not including x randomobject.next ( x, y ) Returns a number between x and up to but not including y Class Random_ Example Random rand = new Random(); int value; value = rand.next(); // [0; 2,147,483,647] value = rand.next( 6 ); // [0; 5] value = rand.next( 1, 7 ); // [1,6] 12

11Debugging and Handling. C# Programming: From Problem Analysis to Program Design 2nd Edition. David McDonald, Ph.D. Director of Emerging Technologies

11Debugging and Handling. C# Programming: From Problem Analysis to Program Design 2nd Edition. David McDonald, Ph.D. Director of Emerging Technologies 11Debugging and Handling 11Exceptions C# Programming: From Problem Analysis to Program Design 2nd Edition David McDonald, Ph.D. Director of Emerging Technologies Chapter Objectives Learn about exceptions,

More information

Debugging and Handling Exceptions

Debugging and Handling Exceptions 12 Debugging and Handling Exceptions C# Programming: From Problem Analysis to Program Design C# Programming: From Problem Analysis to Program Design 1 4th Edition Chapter Objectives Learn about exceptions,

More information

Error Handling. Exceptions

Error Handling. Exceptions Error Handling Exceptions Error Handling in.net Old way (Win32 API and COM): MyFunction() error_1 = dosomething(); if (error_1) display error else continue processing if (error_2) display error else continue

More information

Methods: A Deeper Look

Methods: A Deeper Look 1 2 7 Methods: A Deeper Look OBJECTIVES In this chapter you will learn: How static methods and variables are associated with an entire class rather than specific instances of the class. How to use random-number

More information

Question And Answer.

Question And Answer. Q.1 Which type of of the following code will throw? Using System; Using system.io; Class program Static void Main() Try //Read in non-existent file. Using (StreamReader reader = new StreamReader(^aEURoeI-Am

More information

Chapter 1 Getting Started

Chapter 1 Getting Started Chapter 1 Getting Started The C# class Just like all object oriented programming languages, C# supports the concept of a class. A class is a little like a data structure in that it aggregates different

More information

Introduction to C# Applications

Introduction to C# Applications 1 2 3 Introduction to C# Applications OBJECTIVES To write simple C# applications To write statements that input and output data to the screen. To declare and use data of various types. To write decision-making

More information

C#.Net. Course Contents. Course contents VT BizTalk. No exam, but laborations

C#.Net. Course Contents. Course contents VT BizTalk. No exam, but laborations , 1 C#.Net VT 2009 Course Contents C# 6 hp approx. BizTalk 1,5 hp approx. No exam, but laborations Course contents Architecture Visual Studio Syntax Classes Forms Class Libraries Inheritance Other C# essentials

More information

After completing this appendix, you will be able to:

After completing this appendix, you will be able to: 1418835463_AppendixA.qxd 5/22/06 02:31 PM Page 879 A P P E N D I X A A DEBUGGING After completing this appendix, you will be able to: Describe the types of programming errors Trace statement execution

More information

Using the Xcode Debugger

Using the Xcode Debugger g Using the Xcode Debugger J Objectives In this appendix you ll: Set breakpoints and run a program in the debugger. Use the Continue program execution command to continue execution. Use the Auto window

More information

#using <System.dll> #using <System.Windows.Forms.dll> using namespace System; using namespace System::Windows::Forms;

#using <System.dll> #using <System.Windows.Forms.dll> using namespace System; using namespace System::Windows::Forms; Lecture #13 Introduction Exception Handling The C++ language provides built-in support for handling anomalous situations, known as exceptions, which may occur during the execution of your program. Exceptions

More information

Le L c e t c ur u e e 5 To T p o i p c i s c t o o b e b e co c v o e v r e ed e Exception Handling

Le L c e t c ur u e e 5 To T p o i p c i s c t o o b e b e co c v o e v r e ed e Exception Handling Course Name: Advanced Java Lecture 5 Topics to be covered Exception Handling Exception HandlingHandlingIntroduction An exception is an abnormal condition that arises in a code sequence at run time A Java

More information

Programming Logic - Beginning

Programming Logic - Beginning Programming Logic - Beginning 152-101 Debugging Applications Quick Links & Text References Debugging Concepts Pages Debugging Terminology Pages Debugging in Visual Studio Pages Breakpoints Pages Watches

More information

Introduction to Java. Handout-3a. cs402 - Spring

Introduction to Java. Handout-3a. cs402 - Spring Introduction to Java Handout-3a cs402 - Spring 2003 1 Exceptions The purpose of exceptions How to cause an exception (implicitely or explicitly) How to handle ( catch ) an exception within the method where

More information

.Net Technologies. Components of.net Framework

.Net Technologies. Components of.net Framework .Net Technologies Components of.net Framework There are many articles are available in the web on this topic; I just want to add one more article over the web by explaining Components of.net Framework.

More information

Objectives. Introduce the core C# language features class Main types variables basic input and output operators arrays control constructs comments

Objectives. Introduce the core C# language features class Main types variables basic input and output operators arrays control constructs comments Basics Objectives Introduce the core C# language features class Main types variables basic input and output operators arrays control constructs comments 2 Class Keyword class used to define new type specify

More information

Object Oriented Programming Exception Handling

Object Oriented Programming Exception Handling Object Oriented Programming Exception Handling Budditha Hettige Department of Computer Science Programming Errors Types Syntax Errors Logical Errors Runtime Errors Syntax Errors Error in the syntax of

More information

EW The Source Browser might fail to start data collection properly in large projects until the Source Browser window is opened manually.

EW The Source Browser might fail to start data collection properly in large projects until the Source Browser window is opened manually. EW 25462 The Source Browser might fail to start data collection properly in large projects until the Source Browser window is opened manually. EW 25460 Some objects of a struct/union type defined with

More information

Exception Handling Introduction. Error-Prevention Tip 13.1 OBJECTIVES

Exception Handling Introduction. Error-Prevention Tip 13.1 OBJECTIVES 1 2 13 Exception Handling It is common sense to take a method and try it. If it fails, admit it frankly and try another. But above all, try something. Franklin Delano Roosevelt O throw away the worser

More information

Std 12 Lesson-10 Exception Handling in Java ( 1

Std 12 Lesson-10 Exception Handling in Java (  1 Ch-10 : Exception Handling in Java 1) It is usually understood that a compiled program is error free and will always successfully. (a) complete (b) execute (c) perform (d) accomplish 2) In few cases a

More information

VB Net Debugging (Console)

VB Net Debugging (Console) VB Net Debugging (Console) Introduction A bug is some sort of error in the code which can prevent your program from running properly. When. you write a substantial program always assume that it contains

More information

3. You are writing code for a business application by using C#. You write the following statement to declare an array:

3. You are writing code for a business application by using C#. You write the following statement to declare an array: Lesson 1: Introduction to Programming 1. You need to gain a better understanding of the solution before writing the program. You decide to develop an algorithm that lists all necessary steps to perform

More information

Exception Handling. Sometimes when the computer tries to execute a statement something goes wrong:

Exception Handling. Sometimes when the computer tries to execute a statement something goes wrong: Exception Handling Run-time errors The exception concept Throwing exceptions Handling exceptions Declaring exceptions Creating your own exception Ariel Shamir 1 Run-time Errors Sometimes when the computer

More information

Introduce C# as Object Oriented programming language. Explain, tokens,

Introduce C# as Object Oriented programming language. Explain, tokens, Module 2 98 Assignment 1 Introduce C# as Object Oriented programming language. Explain, tokens, lexicals and control flow constructs. 99 The C# Family Tree C Platform Independence C++ Object Orientation

More information

Debugging INTRODUCTION DEBUGGER WHAT IS VBA'S DEBUGGING ENVIRONMENT?

Debugging INTRODUCTION DEBUGGER WHAT IS VBA'S DEBUGGING ENVIRONMENT? Debugging INTRODUCTION Logic errors are called bugs. The process of finding and correcting errors is called debugging. A common approach to debugging is to use a combination of methods to narrow down to

More information

Exception Handling. Run-time Errors. Methods Failure. Sometimes when the computer tries to execute a statement something goes wrong:

Exception Handling. Run-time Errors. Methods Failure. Sometimes when the computer tries to execute a statement something goes wrong: Exception Handling Run-time errors The exception concept Throwing exceptions Handling exceptions Declaring exceptions Creating your own exception 22 November 2007 Ariel Shamir 1 Run-time Errors Sometimes

More information

Exception Handling in Java. An Exception is a compile time / runtime error that breaks off the

Exception Handling in Java. An Exception is a compile time / runtime error that breaks off the Description Exception Handling in Java An Exception is a compile time / runtime error that breaks off the program s execution flow. These exceptions are accompanied with a system generated error message.

More information

LAB WORK NO. 3 TURBO DEBUGGER ENVIRONMENT

LAB WORK NO. 3 TURBO DEBUGGER ENVIRONMENT LAB WORK NO. 3 TURBO DEBUGGER ENVIRONMENT 1. Objective of the lab work The purpose of this lab is to be able to debug programs written in assembly language and general executables, using a debugging tool.

More information

Appendix G: Writing Managed C++ Code for the.net Framework

Appendix G: Writing Managed C++ Code for the.net Framework Appendix G: Writing Managed C++ Code for the.net Framework What Is.NET?.NET is a powerful object-oriented computing platform designed by Microsoft. In addition to providing traditional software development

More information

About this exam review

About this exam review Final Exam Review About this exam review I ve prepared an outline of the material covered in class May not be totally complete! Exam may ask about things that were covered in class but not in this review

More information

IT 374 C# and Applications/ IT695 C# Data Structures

IT 374 C# and Applications/ IT695 C# Data Structures IT 374 C# and Applications/ IT695 C# Data Structures Module 2.5: Methods A Deeper Look Xianrong (Shawn) Zheng Spring 2017 1 Outline static Methods, static Variables, and Class Math Methods with Multiple

More information

CSC System Development with Java. Exception Handling. Department of Statistics and Computer Science. Budditha Hettige

CSC System Development with Java. Exception Handling. Department of Statistics and Computer Science. Budditha Hettige CSC 308 2.0 System Development with Java Exception Handling Department of Statistics and Computer Science 1 2 Errors Errors can be categorized as several ways; Syntax Errors Logical Errors Runtime Errors

More information

DAD Lab. 1 Introduc7on to C#

DAD Lab. 1 Introduc7on to C# DAD 2017-18 Lab. 1 Introduc7on to C# Summary 1..NET Framework Architecture 2. C# Language Syntax C# vs. Java vs C++ 3. IDE: MS Visual Studio Tools Console and WinForm Applica7ons 1..NET Framework Introduc7on

More information

C#: framework overview and in-the-small features

C#: framework overview and in-the-small features Chair of Software Engineering Carlo A. Furia, Marco Piccioni, Bertrand Meyer C#: framework overview and in-the-small features Chair of Software Engineering Carlo A. Furia, Marco Piccioni, Bertrand Meyer

More information

Programming II (CS300)

Programming II (CS300) 1 Programming II (CS300) Chapter 04: Exception Handling MOUNA KACEM mouna@cs.wisc.edu Fall 2018 Creating Classes 2 Introduction Exception Handling Common Exceptions Exceptions with Methods Assertions and

More information

Introduction to Microsoft.NET

Introduction to Microsoft.NET Introduction to Microsoft.NET.NET initiative Introduced by Microsoft (June 2000) Vision for embracing the Internet in software development Independence from specific language or platform Applications developed

More information

Programming II (CS300)

Programming II (CS300) 1 Programming II (CS300) Chapter 04: Exception Handling MOUNA KACEM mouna@cs.wisc.edu Spring 2018 Creating Classes 2 Introduction Exception Handling Common Exceptions Exceptions with Methods Assertions

More information

Assoc. Prof. Marenglen Biba. (C) 2010 Pearson Education, Inc. All rights reserved.

Assoc. Prof. Marenglen Biba. (C) 2010 Pearson Education, Inc. All rights reserved. Assoc. Prof. Marenglen Biba Exception handling Exception an indication of a problem that occurs during a program s execution. The name exception implies that the problem occurs infrequently. With exception

More information

Exception-Handling Overview

Exception-Handling Overview م.عبد الغني أبوجبل Exception Handling No matter how good a programmer you are, you cannot control everything. Things can go wrong. Very wrong. When you write a risky method, you need code to handle the

More information

Visual C# Instructor s Manual Table of Contents

Visual C# Instructor s Manual Table of Contents Visual C# 2005 2-1 Chapter 2 Using Data At a Glance Instructor s Manual Table of Contents Overview Objectives s Quick Quizzes Class Discussion Topics Additional Projects Additional Resources Key Terms

More information

Program Correctness and Efficiency. Chapter 2

Program Correctness and Efficiency. Chapter 2 Program Correctness and Efficiency Chapter 2 Chapter Objectives To understand the differences between the three categories of program errors To understand the effect of an uncaught exception and why you

More information

Introduction. Exceptions: An OO Way for Handling Errors. Common Runtime Errors. Error Handling. Without Error Handling Example 1

Introduction. Exceptions: An OO Way for Handling Errors. Common Runtime Errors. Error Handling. Without Error Handling Example 1 Exceptions: An OO Way for Handling Errors Introduction Rarely does a program runs successfully at its very first attempt. It is common to make mistakes while developing as well as typing a program. Such

More information

Supplemental Handout: Exceptions CS 1070, Spring 2012 Thursday, 23 Feb 2012

Supplemental Handout: Exceptions CS 1070, Spring 2012 Thursday, 23 Feb 2012 Supplemental Handout: Exceptions CS 1070, Spring 2012 Thursday, 23 Feb 2012 1 Objective To understand why exceptions are useful and why Visual Basic has them To gain experience with exceptions and exception

More information

Project Compiler. CS031 TA Help Session November 28, 2011

Project Compiler. CS031 TA Help Session November 28, 2011 Project Compiler CS031 TA Help Session November 28, 2011 Motivation Generally, it s easier to program in higher-level languages than in assembly. Our goal is to automate the conversion from a higher-level

More information

The NetBeans Debugger: A Brief Tutorial

The NetBeans Debugger: A Brief Tutorial The NetBeans Debugger: A Brief Tutorial Based on a tutorial by Anousha Mesbah from the University of Georgia NetBeans provides a debugging tool that lets you trace the execution of a program step by step.

More information

Debugging Code in Access 2002

Debugging Code in Access 2002 0672321025 AppA 10/24/01 3:53 PM Page 1 Debugging Code in Access 2002 APPENDIX A IN THIS APPENDIX Setting the Correct Module Options for Maximum Debugging Power 2 Using the Immediate Window 6 Stopping

More information

Visual Studio.NET.NET Framework. Web Services Web Forms Windows Forms. Data and XML classes. Framework Base Classes. Common Language Runtime

Visual Studio.NET.NET Framework. Web Services Web Forms Windows Forms. Data and XML classes. Framework Base Classes. Common Language Runtime Intro C# Intro C# 1 Microsoft's.NET platform and Framework.NET Enterprise Servers Visual Studio.NET.NET Framework.NET Building Block Services Operating system on servers, desktop, and devices Web Services

More information

Zend Studio 3.0. Quick Start Guide

Zend Studio 3.0. Quick Start Guide Zend Studio 3.0 This walks you through the Zend Studio 3.0 major features, helping you to get a general knowledge on the most important capabilities of the application. A more complete Information Center

More information

Chapter 2: Using Data

Chapter 2: Using Data Chapter 2: Using Data Declaring Variables Constant Cannot be changed after a program is compiled Variable A named location in computer memory that can hold different values at different points in time

More information

Lecture 20. Java Exceptional Event Handling. Dr. Martin O Connor CA166

Lecture 20. Java Exceptional Event Handling. Dr. Martin O Connor CA166 Lecture 20 Java Exceptional Event Handling Dr. Martin O Connor CA166 www.computing.dcu.ie/~moconnor Topics What is an Exception? Exception Handler Catch or Specify Requirement Three Kinds of Exceptions

More information

BasicScript 2.25 User s Guide. May 29, 1996

BasicScript 2.25 User s Guide. May 29, 1996 BasicScript 2.25 User s Guide May 29, 1996 Information in this document is subject to change without notice. No part of this document may be reproduced or transmitted in any form or by any means, electronic

More information

Day 8. COMP1006/1406 Summer M. Jason Hinek Carleton University

Day 8. COMP1006/1406 Summer M. Jason Hinek Carleton University Day 8 COMP1006/1406 Summer 2016 M. Jason Hinek Carleton University today s agenda assignments Assignment 4 is out and due on Tuesday Bugs and Exception handling 2 Bugs... often use the word bug when there

More information

Tutorial 6 Enhancing the Inventory Application Introducing Variables, Memory Concepts and Arithmetic

Tutorial 6 Enhancing the Inventory Application Introducing Variables, Memory Concepts and Arithmetic Tutorial 6 Enhancing the Inventory Application Introducing Variables, Memory Concepts and Arithmetic Outline 6.1 Test-Driving the Enhanced Inventory Application 6.2 Variables 6.3 Handling the TextChanged

More information

Introduction to Programming Using Java (98-388)

Introduction to Programming Using Java (98-388) Introduction to Programming Using Java (98-388) Understand Java fundamentals Describe the use of main in a Java application Signature of main, why it is static; how to consume an instance of your own class;

More information

C++\CLI. Jim Fawcett CSE687-OnLine Object Oriented Design Summer 2017

C++\CLI. Jim Fawcett CSE687-OnLine Object Oriented Design Summer 2017 C++\CLI Jim Fawcett CSE687-OnLine Object Oriented Design Summer 2017 Comparison of Object Models Standard C++ Object Model All objects share a rich memory model: Static, stack, and heap Rich object life-time

More information

7 The Integrated Debugger

7 The Integrated Debugger 7 The Integrated Debugger Your skill set for writing programs would not be complete without knowing how to use a debugger. While a debugger is traditionally associated with finding bugs, it can also be

More information

Lab 8 - Vectors, and Debugging. Directions

Lab 8 - Vectors, and Debugging. Directions Lab 8 - Vectors, and Debugging. Directions The labs are marked based on attendance and effort. It is your responsibility to ensure the TA records your progress by the end of the lab. While completing these

More information

Under the Debug menu, there are two menu items for executing your code: the Start (F5) option and the

Under the Debug menu, there are two menu items for executing your code: the Start (F5) option and the CS106B Summer 2013 Handout #07P June 24, 2013 Debugging with Visual Studio This handout has many authors including Eric Roberts, Julie Zelenski, Stacey Doerr, Justin Manis, Justin Santamaria, and Jason

More information

Standard. Number of Correlations

Standard. Number of Correlations Computer Science 2016 This assessment contains 80 items, but only 80 are used at one time. Programming and Software Development Number of Correlations Standard Type Standard 2 Duty 1) CONTENT STANDARD

More information

5/19/2015. Objectives. JavaScript, Sixth Edition. Understanding Syntax Errors. Introduction to Debugging. Handling Run-Time Errors

5/19/2015. Objectives. JavaScript, Sixth Edition. Understanding Syntax Errors. Introduction to Debugging. Handling Run-Time Errors Objectives JavaScript, Sixth Edition Chapter 4 Debugging and Error Handling When you complete this chapter, you will be able to: Recognize error types Trace errors with dialog boxes and the console Use

More information

VISUAL PROGRAMMING_IT0309 Semester Number 05. G.Sujatha & R.Vijayalakshmi Assistant professor(o.g) SRM University, Kattankulathur

VISUAL PROGRAMMING_IT0309 Semester Number 05. G.Sujatha & R.Vijayalakshmi Assistant professor(o.g) SRM University, Kattankulathur School of Computing, 12/26/2012 1 VISUAL PROGRAMMING_IT0309 Semester Number 05 G.Sujatha & R.Vijayalakshmi Assistant professor(o.g) SRM University, Kattankulathur UNIT 1 School of Computing, Department

More information

1.00 Lecture 2. What s an IDE?

1.00 Lecture 2. What s an IDE? 1.00 Lecture 2 Interactive Development Environment: Eclipse Reading for next time: Big Java: sections 3.1-3.9 (Pretend the method is main() in each example) What s an IDE? An integrated development environment

More information

Question And Answer.

Question And Answer. Q.1 What would be the output of the following program? using System; namespaceifta classdatatypes static void Main(string[] args) inti; Console.WriteLine("i is not used inthis program!"); A. i is not used

More information

QUIZ How do we implement run-time constants and. compile-time constants inside classes?

QUIZ How do we implement run-time constants and. compile-time constants inside classes? QUIZ How do we implement run-time constants and compile-time constants inside classes? Compile-time constants in classes The static keyword inside a class means there s only one instance, regardless of

More information

Getting Started (1.8.7) 9/2/2009

Getting Started (1.8.7) 9/2/2009 2 Getting Started For the examples in this section, Microsoft Windows and Java will be used. However, much of the information applies to other operating systems and supported languages for which you have

More information

Lecture 14: Exceptions 10:00 AM, Feb 26, 2018

Lecture 14: Exceptions 10:00 AM, Feb 26, 2018 CS18 Integrated Introduction to Computer Science Fisler, Nelson Lecture 14: Exceptions 10:00 AM, Feb 26, 2018 Contents 1 Exceptions and How They Work 1 1.1 Update to the Banking Example.............................

More information

Lesson 02 Working with Data Types. MIT 31043: VISUAL PROGRAMMING By: S. Sabraz Nawaz Senior Lecturer in MIT

Lesson 02 Working with Data Types. MIT 31043: VISUAL PROGRAMMING By: S. Sabraz Nawaz Senior Lecturer in MIT Lesson 02 Working with Data Types MIT 31043: VISUAL PROGRAMMING Senior Lecturer in MIT Variables A variable is a storage location in memory that is represented by a name. A variable stores data, which

More information

Online Activity: Debugging and Error Handling

Online Activity: Debugging and Error Handling Online Activity: Debugging and Error Handling In this activity, you are to carry a number of exercises that introduce you to the world of debugging and error handling in ASP.NET using C#. Copy the application

More information

Section 1 AVR Studio User Guide

Section 1 AVR Studio User Guide Section 1 AVR Studio User Guide 1.1 Introduction Welcome to AVR Studio from Atmel Corporation. AVR Studio is a Development Tool for the AVR family of microcontrollers. This manual describes the how to

More information

Exceptions and Error Handling

Exceptions and Error Handling Exceptions and Error Handling Michael Brockway January 16, 2015 Some causes of failures Incorrect implementation does not meet the specification. Inappropriate object request invalid index. Inconsistent

More information

SQL Server. Management Studio. Chapter 3. In This Chapter. Management Studio. c Introduction to SQL Server

SQL Server. Management Studio. Chapter 3. In This Chapter. Management Studio. c Introduction to SQL Server Chapter 3 SQL Server Management Studio In This Chapter c Introduction to SQL Server Management Studio c Using SQL Server Management Studio with the Database Engine c Authoring Activities Using SQL Server

More information

CS 231 Data Structures and Algorithms, Fall 2016

CS 231 Data Structures and Algorithms, Fall 2016 CS 231 Data Structures and Algorithms, Fall 2016 Dr. Bruce A. Maxwell Department of Computer Science Colby College Course Description Focuses on the common structures used to store data and the standard

More information

CIS133J. Working with Numbers in Java

CIS133J. Working with Numbers in Java CIS133J Working with Numbers in Java Contents: Using variables with integral numbers Using variables with floating point numbers How to declare integral variables How to declare floating point variables

More information

Getting started 7. Storing values 21. Creating variables 22 Reading input 24 Employing arrays 26 Casting data types 28 Fixing constants 30 Summary 32

Getting started 7. Storing values 21. Creating variables 22 Reading input 24 Employing arrays 26 Casting data types 28 Fixing constants 30 Summary 32 Contents 1 2 3 Contents Getting started 7 Introducing C# 8 Installing Visual Studio 10 Exploring the IDE 12 Starting a Console project 14 Writing your first program 16 Following the rules 18 Summary 20

More information

COMP 213. Advanced Object-oriented Programming. Lecture 17. Exceptions

COMP 213. Advanced Object-oriented Programming. Lecture 17. Exceptions COMP 213 Advanced Object-oriented Programming Lecture 17 Exceptions Errors Writing programs is not trivial. Most (large) programs that are written contain errors: in some way, the program doesn t do what

More information

Name: Class: Date: 2. Today, a bug refers to any sort of problem in the design and operation of a program.

Name: Class: Date: 2. Today, a bug refers to any sort of problem in the design and operation of a program. Name: Class: Date: Chapter 6 Test Bank True/False Indicate whether the statement is true or false. 1. You might be able to write statements using the correct syntax, but be unable to construct an entire,

More information

Chapter 9: Dealing with Errors

Chapter 9: Dealing with Errors Chapter 9: Dealing with Errors What we will learn: How to identify errors Categorising different types of error How to fix different errors Example of errors What you need to know before: Writing simple

More information

CS 112 Introduction to Computing II. Wayne Snyder Computer Science Department Boston University

CS 112 Introduction to Computing II. Wayne Snyder Computer Science Department Boston University CS 112 Introduction to Computing II Wayne Snyder Department Boston University Today: Java basics: Compilation vs Interpretation Program structure Statements Values Variables Types Operators and Expressions

More information

INDEX. A SIMPLE JAVA PROGRAM Class Declaration The Main Line. The Line Contains Three Keywords The Output Line

INDEX. A SIMPLE JAVA PROGRAM Class Declaration The Main Line. The Line Contains Three Keywords The Output Line A SIMPLE JAVA PROGRAM Class Declaration The Main Line INDEX The Line Contains Three Keywords The Output Line COMMENTS Single Line Comment Multiline Comment Documentation Comment TYPE CASTING Implicit Type

More information

CS 61B Data Structures and Programming Methodology. July 7, 2008 David Sun

CS 61B Data Structures and Programming Methodology. July 7, 2008 David Sun CS 61B Data Structures and Programming Methodology July 7, 2008 David Sun Announcements You ve started (or finished) project 1, right? Package Visibility public declarations represent specifications what

More information

Lesson 02 Working with Data Types MIT 31043, Visual Programming By: S. Sabraz Nawaz

Lesson 02 Working with Data Types MIT 31043, Visual Programming By: S. Sabraz Nawaz Lesson 02 Working with Data Types MIT 31043, Visual Programming By: S. Sabraz Nawaz Senior Lecturer in MIT Department of MIT Faculty of Management and Commerce South Eastern University of Sri Lanka Variables

More information

Introduction to Java https://tinyurl.com/y7bvpa9z

Introduction to Java https://tinyurl.com/y7bvpa9z Introduction to Java https://tinyurl.com/y7bvpa9z Eric Newhall - Laurence Meyers Team 2849 Alumni Java Object-Oriented Compiled Garbage-Collected WORA - Write Once, Run Anywhere IDE Integrated Development

More information

Object oriented programming. Instructor: Masoud Asghari Web page: Ch: 7

Object oriented programming. Instructor: Masoud Asghari Web page:   Ch: 7 Object oriented programming Instructor: Masoud Asghari Web page: http://www.masses.ir/lectures/oops2017sut Ch: 7 1 In this slide We follow: https://docs.oracle.com/javase/tutorial/index.html Trail: Essential

More information

Software Engineering

Software Engineering Software Engineering Lecture 12: Testing and Debugging Debugging Peter Thiemann University of Freiburg, Germany 13.06.2013 Today s Topic Last Lecture Bug tracking Program control Design for Debugging Input

More information

Exceptions in Java

Exceptions in Java Exceptions in Java 3-10-2005 Opening Discussion Do you have any questions about the quiz? What did we talk about last class? Do you have any code to show? Do you have any questions about the assignment?

More information

Error Handling for the User Interface O BJECTIVES

Error Handling for the User Interface O BJECTIVES 08 0789728222 CH04 4/7/03 11:03 AM Page 281 O BJECTIVES This chapter covers the following Microsoft-specified objectives for the Creating User Services section of Exam 70-315, Developing and Implementing

More information

Exception handling & logging Best Practices. Angelin

Exception handling & logging Best Practices. Angelin Exception handling & logging Best Practices Angelin AGENDA Logging using Log4j Logging Best Practices Exception Handling Best Practices CodePro Errors and Fixes Logging using Log4j Logging using Log4j

More information

Introduction to C# Applications Pearson Education, Inc. All rights reserved.

Introduction to C# Applications Pearson Education, Inc. All rights reserved. 1 3 Introduction to C# Applications 2 What s in a name? That which we call a rose by any other name would smell as sweet. William Shakespeare When faced with a decision, I always ask, What would be the

More information

Visual Studio.NET. Although it is possible to program.net using only the command OVERVIEW OF VISUAL STUDIO.NET

Visual Studio.NET. Although it is possible to program.net using only the command OVERVIEW OF VISUAL STUDIO.NET Chapter. 03 9/17/01 6:08 PM Page 35 Visual Studio.NET T H R E E Although it is possible to program.net using only the command line compiler, it is much easier and more enjoyable to use Visual Studio.NET.

More information

CS558 Programming Languages

CS558 Programming Languages CS558 Programming Languages Fall 2016 Lecture 3a Andrew Tolmach Portland State University 1994-2016 Formal Semantics Goal: rigorous and unambiguous definition in terms of a wellunderstood formalism (e.g.

More information

Lecture 5: Methods CS2301

Lecture 5: Methods CS2301 Lecture 5: Methods NADA ALZAHRANI CS2301 1 Opening Problem Find the sum of integers from 1 to 10, from 20 to 30, and from 35 to 45, respectively. 2 Solution public static int sum(int i1, int i2) { int

More information

Pace University. Fundamental Concepts of CS121 1

Pace University. Fundamental Concepts of CS121 1 Pace University Fundamental Concepts of CS121 1 Dr. Lixin Tao http://csis.pace.edu/~lixin Computer Science Department Pace University October 12, 2005 This document complements my tutorial Introduction

More information

Debugging in Small Basic is the process of analysing a program to detect and fix errors or improve functionality in some way.

Debugging in Small Basic is the process of analysing a program to detect and fix errors or improve functionality in some way. How to Debug Introduction Debugging in Small Basic is the process of analysing a program to detect and fix errors or improve functionality in some way. In order to debug a program it must first compile

More information

C# Fundamentals. built in data types. built in data types. C# is a strongly typed language

C# Fundamentals. built in data types. built in data types. C# is a strongly typed language C# Fundamentals slide 2 C# is a strongly typed language the C# compiler is fairly good at finding and warning about incorrect use of types and uninitialised and unused variables do not ignore warnings,

More information

CHAPTER 5: EXCEPTION & OBJECT LIFETIME

CHAPTER 5: EXCEPTION & OBJECT LIFETIME CHAPTER 5: EXCEPTION & OBJECT LIFETIME ERRORS, BUGS & EXCEPTION Keywords Meaning Errors These are caused by end-user of the application. For e.g., entering un-expected value in a textbox, say USN. Bugs

More information

Tokens, Expressions and Control Structures

Tokens, Expressions and Control Structures 3 Tokens, Expressions and Control Structures Tokens Keywords Identifiers Data types User-defined types Derived types Symbolic constants Declaration of variables Initialization Reference variables Type

More information

A Fast Review of C Essentials Part I

A Fast Review of C Essentials Part I A Fast Review of C Essentials Part I Structural Programming by Z. Cihan TAYSI Outline Program development C Essentials Functions Variables & constants Names Formatting Comments Preprocessor Data types

More information

A Tutorial for ECE 175

A Tutorial for ECE 175 Debugging in Microsoft Visual Studio 2010 A Tutorial for ECE 175 1. Introduction Debugging refers to the process of discovering defects (bugs) in software and correcting them. This process is invoked when

More information

Computer Science II Lab 3 Testing and Debugging

Computer Science II Lab 3 Testing and Debugging Computer Science II Lab 3 Testing and Debugging Introduction Testing and debugging are important steps in programming. Loosely, you can think of testing as verifying that your program works and debugging

More information

Introduction. Key features and lab exercises to familiarize new users to the Visual environment

Introduction. Key features and lab exercises to familiarize new users to the Visual environment Introduction Key features and lab exercises to familiarize new users to the Visual environment January 1999 CONTENTS KEY FEATURES... 3 Statement Completion Options 3 Auto List Members 3 Auto Type Info

More information