Validating User Input Lesson 5.

Slides:



Advertisements
Similar presentations
Error-handling using exceptions
Advertisements

(Using.NET Platform) Note: Most of the material in these slides have been adapted from MSDN and wikipedia. By Muhammad Ali.
CS7026 jQuery Events. What are Events?  jQuery is tailor-made to respond to events in an HTML page.  Events are actions that can be detected by your.
Try…Catch…Finally Blocks ( continued ) Generic catch clause –Omit argument list with the catch –Any exception thrown is handled by executing code within.
C# Programming: From Problem Analysis to Program Design1 Debugging and Handling Exceptions C# Programming: From Problem Analysis to Program Design 3 rd.
Chapter 11 Debugging and Handling Exceptions
Microsoft VB 2005: Reloaded, Advanced Chapter 5 Input Validation, Error Handling, and Exception Handling.
© by Pearson Education, Inc. All Rights Reserved.
Exception Handling An Exception is an indication of a problem that occurs during a program’s execution. Exception handling enables the programmer to create.
1 An Introduction to Visual Basic Objectives Explain the history of programming languages Define the terminology used in object-oriented programming.
CS0004: Introduction to Programming Events. Review  Event Procedure  A set of instructions to be executed when a certain event happens.  Many event-driven.
COMPUTER PROGRAMMING 2 Exceptions. What are Exceptions? Unexpected events that happen when the code is executing (during runtime). Exceptions are types.
Pemrograman VisualMinggu …12… Page 1 MINGGU Ke Duabelas Pemrograman Visual Pokok Bahasan: Exception Handling Tujuan Instruksional Khusus: Mahasiswa dapat.
CIS 3301 C# Lesson 13 Interfaces. CIS 3302 Objectives Understand the Purpose of Interfaces. Define an Interface. Use an Interface. Implement Interface.
Lecture Set 13 Drawing Mouse and Keyboard Events Part B – Mouse and Keyboard Events.
Java Programming: Guided Learning with Early Objects
Timer, Animation Responding to Mouse & Keyboard Lab 7 7 McGraw-Hill© 2006 The McGraw-Hill Companies, Inc. All rights reserved.
Introduction to Exception Handling and Defensive Programming.
Visual Basic.NET BASICS Lesson 5 Exponentiation, Order of Operations, and Error Handling.
Chapter 12 Handling Exceptions and Events. Chapter Objectives Learn what an exception is Become aware of the hierarchy of exception classes Learn about.
JAVA COURSE LESSON2 BY OMPUTER ENGINEEING ASSOCIATION.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 4: Events Programming with Alice and Java First Edition by John Lewis.
CHAPTER 6 LESSON B Creating Custom Forms. Lesson B Objectives  Suppress default system messages  Create alerts and messages to provide system feedback.
Host Objects: Browsers and the DOM
Overview of Previous Lesson(s) Over View  ASP is a technology that enables scripts in web pages to be executed by an Internet server.  ASP.NET is a.
Text INTRODUCTION TO ASP.NET. InterComm Campaign Guidelines CONFIDENTIAL Simply Server side language Simplified page development model Modular, well-factored,
C# Exceptions 1 CNS 3260 C#.NET Software Development.
Implement User Input Windows Development Fundamentals LESSON 2.4A.
1 Handling Errors and Exceptions Chapter 6. 2 Objectives You will be able to: 1. Use the try, catch, and finally statements to handle exceptions. 2. Raise.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Enhanced Car Payment Calculator Application Introducing Exception Handling.
Eighth Lecture Exception Handling in Java
Dive Into® Visual Basic 2010 Express
Visual Basic Fundamental Concepts
ASP.NET Programming with C# and SQL Server First Edition
Debugging and Handling Exceptions
Important New Concepts In WPF
Advanced User Interfaces
Introduction to Event-Driven Programming
Chapter Topics 15.1 Graphical User Interfaces
Computer Programming I
Chapter 5: Programming with C#
Visual programming Chapter 1: Introduction
Indexer AKEEL AHMED.
Lesson 1: Buttons and Events – 12/18
Exception Handling .NET MVC
Visual Basic Properties, Methods and Events
CNS 3260 C# .NET Software Development
Visual Basic..
Hands-on Introduction to Visual Basic .NET
Chapter 12 Exception Handling and Text IO
Exception Handling Chapter 9 Edited by JJ.
Part B – Structured Exception Handling
Exception Handling By: Enas Naffar.
Introduction to jQuery
1/10/2019 JavaFX Events COSC 330.
Programming in C# Lesson 5. Exceptions..
Programming in C# CHAPTER - 7
Exception Handling Imran Rashid CTO at ManiWeber Technologies.
Exception Handling and Event Handling
Lecture 11 Objectives Learn what an exception is.
Chapter 15: GUI Applications & Event-Driven Programming
JavaScript and Events CS Programming Languages for Web Applications
Tenth step for Learning C++ Programming
Introduction to Programming
Chapter 13: Handling Events
Debugging and Handling Exceptions
CS7026 jQuery Events.
CMSC 202 Exceptions.
Java Programming: From Problem Analysis to Program Design, 4e
JavaScript and Events CS Programming Languages for Web Applications
Presentation transcript:

Validating User Input Lesson 5

Objectives

Windows Users input Model Windows Forms and WPF applications are constantly receiving user inputs from the keyboard, mouse, and stylus. Knowing when to handle user input events will enable the application to maintain performance and provide a better user experience. Table 4-1 shows common Windows Form Events

Windows Users input Model When analyzing the application requirements and designing your Form/Window UI, you need to consider at what level you want to handle each user input device action being generated. The three user input processing levels are: Device Action Control Action Form/Window Action

Input Device User Inputs Windows applications currently support three types of input devices: Keyboard Mouse Stylus As a user interacts with an input device, actions are generated and your windows application can implement event handlers.

Keyboard User Inputs Although both Windows Forms and WPF applications support keyboard user inputs, they have different events to support keyboard user input processing. Common Keyboard User Input Events include: KeyDown KeyPress KeyUp GotKeyboardFocus PreviewKeyDown LostKeyboardFocus PreviewKeyUp

Mouse User Inputs Both Windows Forms and WPF applications support mouse user inputs. Although they both support mouse user inputs, they have different events to support mouse user input processing. Common Mouse User Inputs include: MouseUp MouseDown MouseEnter MouseLeave MouseMove GotMouseCapture LostMouseCapture WheelMove MouseClick MouseDoubleClick

Tablet Support New to WPF applications is the default support for the stylus input device. With the advent of the Tablet PC and touch screens, more applications are requiring the user to interact with stylus input devices. By default, Windows Forms do not support stylus input devices, but you can download the Table PC Software Development Kit (SDK) to integrate stylus support into your Windows Forms application.

Common Stylus User Inputs include: Many of the same events for the keyboard and mouse are supported for the stylus. Common Stylus User Inputs include: StylusButtonUp StylusButtonDown StylusUp StylusDown StylusMove StylusInAirMove StylusOutOfRange StylusInRange

Control User Inputs Not all user input device events are generated by a specific type of input device. Some user input device events are generated by a variety of device types and handled by the Control and/or Form/Window. Common Control User Inputs include: Click DoubleClick GotFocus LostFocus Validating Validated

Form/Windows Level Control User Input In addition to Control level user input events, you also have Form/Windows level user input events. The Form/Window level user input events are both reactions to user input devices and to validation processing.

Exceptions During the validation process, you will encounter situations where the user has entered text into a number field or entered a decimal number into an integer field. When you try to validate these types of situations, Visual Studio will encounter an error and throw an Exception. An Exception is a runtime error that will halt the execution of the application unless handled.

Exception Classes The Exception class is a part of the System namespace and handles all runtime error handling. When an Exception occurs, the error is handled either by the System Exception Handler or by a specific application Exception Handler. Exception handling can be categorized into two basic types: Common Language Runtime (CLR) Exceptions User-Defined Exceptions

Common Properties of the Exception Class HelpLink Message Source StackTrace

Trapping Exceptions Allowing the default Visual Studio Exception handler to take care of all your Exceptions is not a best practice and will cause the application to exit execution any time an unhandled Exception is raised. It is a best practice to implement your own Exception handling routines.

Trapping Exceptions Exceptions are trapped in Visual Studio using the Try-Catch-Finally statement. try { // Try to perform some processing … } catch (Exception ex) // Process exception finally // No matter what, these are the things // I still want to perform

Exception Catch Block Once the Exception is raised, the Catch block begins to execute. In the Catch block, you will try to figure out which Exception has occurred and what to do with the Exception. There are several actions you can take when you encounter an Exception in the Catch block: Ignore User Determined Halt Execution

Throwing Exceptions You can respond to System Exceptions or you can raise your own custom Exceptions. Much like any other class in the .NET Framework, the Exception class can be derived and extended to perform custom Exception handling. Some derived classes like the OutOfMemoryException can also be inherited and extended, but other derived classes like the StackOverflowException cannot be inherited.

Summary You learned about the Windows User Input Model and the various device input action levels. You learned about Keyboard, Mouse, and Stylus events and their device input action levels. You learned how to create Keyboard, Mouse, and Stylus Event Handler methods. You learned about the Exception class and various derived Exception classes. You learned how to handle various Exceptions and how to raise a custom Exception.