Question And Answer.

Size: px
Start display at page:

Download "Question And Answer."

Transcription

1 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 ^aeur"not-present.txt^aeur Q.2 Which of the following statements are correct about exception handling in C#.NET? I. try blocks cannot be nested. II. In one function, there can be only one try block. III. An exception must be caught in the same function in which it is thrown. IV. All values set up in the exception object are available in the catch block. V. While throwing a user-defined exception multiple values can be set in the exception, object. A. I only B. I and II only C. III only D. IV and V only ANSWER : Option B I and II only option 1st isincorrecttryblockcan not be nested because try may nested Option 2nd is incorrect because in one functions there can be more than one try block as we already discuss try may nested Option 4th and 5th is correct because for every try there must be have a catch block Q.3 Can I use exceptions in C#? A. Yes. B. No. C. D. ANSWER : Option A Yes. In fact exceptions are the recommended error-handling mechanism in C#. Q.4 Which of the following statement are correct about exception handling in c#.net? Page 1

2 I. If our program does not catch an exception then the.net CLR catches it. II. It is possible to create user defined exception. III. All types of exception can be caught using the Exception class. IV. CLR Exceptionsis the base class for all exception classes. V. For every try block there must be a corresponding finally block. A. I and II. B. I, II and III. C. IV and V. D. All the above ANSWER : Option B I, II and III. When an exception is thrown, the common language runtime (CLR) looks for the catch statement that handles this exception. If the currently executing method does not contain such a catch block, the CLR looks at the method that called the current method, and so on up the call stack. If no catch block is found, then the CLR displays an unhandled exception message to the user and stops execution of the program. If you want users to be able to programmatically distinguish between some error conditions, you can create your own user-defined exceptions. The.NET Framework provides a hierarchy of exception classes ultimately derived from the base class Exception. Each of these classes defines a specific exception, so in many cases you only have to catch the exception. You can also create your own exception classes by deriving from the Exception class. When creating your own exceptions, it is good coding practice to end the class name of the user-defined exception with the word "Exception." C# exceptions are represented by classes. The exception classes in C# are mainly directly or indirectly derived from the System.Exception class. Some of the exception classes derived from the System.Exception class are the System.ApplicationException and System.SystemExceptionclasses.The System.ApplicationException class supports exceptions generated by application programs. So the exceptions defined by the programmers should derive from this class. The System.SystemException class is the base class for all predefined system exception. Q.5 Which of the following statements are correct about exception handling in C#.NET? I. If our program does not catch an exception then the.net CLR catches it. II. It is possible to create user-defined exceptions. III. All types of exceptions can be caught using the Exception class. IV. CLR Exceptions is the base class for all exception classes. V. For every try block there must be a corresponding finally block. Page 2

3 A. Iand II only B. I, II and III only C. IV and V only D. All of the above ANSWER : Option B I, II and III only When an exception is thrown, the common language runtime (CLR) looks for the catch statement that handles this exception. If the currently executing method does not contain such a catch block, the CLR looks at the method that called the current method, and so on up the call stack. If no catch block is found, then the CLR displays an unhandled exception message to the user and stops execution of the program. Q.6 Which of the following is NOT a.net Exception class? A. Exception B. StackMemoryException C. DivideByZeroException D. OutOfMemoryException ANSWER : Option B StackMemoryException Because the heap memory is controlled by memory management of.net. Q.7 Which of the following are properties of Exception Type? A. Message B. Source C. StackTrace D. All the above ANSWER : Option D All the above Message : This is a short description of the exceptions cause. Message is a read only string property. Source : This is the application name. source is a string property that can be assigned to or read from. StackTrace : This is the path through the compiled programs method hierarchy that the exception was generated from. Q.8 Does the System.Exception class have any cool features? A. Yes. B. No. C. D. Page 3

4 ANSWER : Option A Yes. The feature which stands out is the StackTrace property. This provides a call stack which records where the exception was thrown from. Q.9 Can we have multiple catch blocks with try block? Try //Code that can generate exception Catch(System.DivideByZeroException ex) //code to handle the divide by zero exception Catch(system.ArithmaticException ex) // Code to handle the arithmatic exception A. Yes B. No C. D. ANSWER : Option A Yes Yes we can have as any number of catch blocks with a try block Though each catch block should catch a different exception. The order of catch block is important,because the catch block are examined in order. User should always catch the more specific exception before than the less specific one.the compiler will produce an error if order your catch block so that a later block will never be reached. Try //Code that can generate exception Catch(System.Exception ex) //code to handle the divide by zero exception Catch(system.ArithmaticException ex) // Code to handle the arithmatic exception The above code will produce a compile time error^aeur Page 4

5 Q.10 What would be the output of following code snippet? Try A==10/0; Console.WriteLine(a); Catch (System.DivideByZeroException ex) Console.WriteLine(^aEURoedivide by zero exception^aeur Q.11 Which of the following statements are correct about exception handling in C#.NET? I. If an exception occurs then the program terminates abruptly without getting any chance to recover from the exception. II. No matter whether an exception occurs or not, the statements in the finally clause (if present) will get executed. III. A program can contain multiple finally clauses. IV. A finally clause is written outside the try block. V. finally clause is used to perform clean up operations like closing the network/database connections. A. I only B. II only C. II and V only D. III and IV only ANSWER : Option C II and V only In that Finally is not Class, it is block. It is optional also to include in try catch. But when use Try statement, at least one catch statement should present. Throw will also option, it is used only user want to throw user exception. Q.12 Which of the following options is a C#.NET exception class? (Multiple Choice) A. ArithmeticException & ArrayTypeMismatchException. B. DivideByZeroException & IndexOutOfRangeException. C. InvalidCastException & NullReferenceException. D. All the above. ANSWER : Option D All the above. We have few more common exception classes such as Exception, Stack Overflow Exception and Type Initialization Exception. Q.13 Is the following true about stack trace? A. Gets a string representation of the immediate frames on the call stack. Page 5

6 B. It is commonly used during interactive and post-mortem debugging. It can also be to the user of a program as part of an error message,which a user can report to a programmer. C. A stack trace allows to track the sequence of nested functions called up to the point where the stack trace is generated. In a post-mortem scenario this is up to function where the failure occurred. D. All of the above. ANSWER : Option D All of the above. Stack Trace is a property of exception object. The stack trace property lists method calls in reverse chronological order,that is, the most recent method call is described first, and one line of stack trace information is listed for each method call on the stack.however,the stack trace property might not report as many method calls as expected due to code transformations that occur during optimization. Q.14 Select which among is NOT an exception? A. Stack Overflow B. Arithmetic Overflow or underflow C. Incorrect Arithmetic Expression D. All of the above mentioned ANSWER : Option C Incorrect Arithmetic Expression The CLR is being run in a hosted environment where the host specifically allows for StackOverflow exceptions to be handled. The stackoverflow exception is thrown by user code and not due to an actual stack overflow situation.arith^a-metic oper^a-a^a-tions and con^a-ver^a-sions in C# are exe^a-cuted in an unchecked con^a-text. This means that for a signed inte^a-ger it over^a-flows from int.maxvalue to int.minvalue and under^a-flows from int.minvalue to int.maxvalue, hence both state^a-ments below eval^a-u^a-ates to true: (int.minvalue ^aeur" 1) == int.maxvalue; (int.maxvalue + 1) == int.minvalue; Sim^A-i^A-larly, for an unsigned inte^a-ger it will under^a-flow from 0 to uint.maxvalue and over^a-flow from uint. MaxValue to 0: (0 ^aeur" 1) == uint.maxvalue; // uint.minvalue = 0 (uint.maxvalue + 1) == 0; Q.15 In C#.NET if we do not catch the exception thrown at runtime then which of the following will catch it? Page 6

7 A. Compiler B. CLR C. Linker D. Loader ANSWER : Option B CLR Exception occurs at runtime because clear catches. Q.16 Choose the correct output for given set of code: static void Main(string[] args) try Console.WriteLine("csharp" + " " + 1/Convert.ToInt32(0)); catch(arithmeticexception e) Console.WriteLine("Java"); Console.ReadLine(); A. Csharp. B. Java. C. Run time error. D. csharp 0 ANSWER : Option B Java. 1 / 0, hence system out of flow exception error. Q.17 Which type of exception the following code will throw? Class program Static void Main() String value = ^aeuroetest^aeur Q.18 From which base class all exceptions are derived from? A. System.Exception B. System.Error.Exception C. System.Error D. System.Fault ANSWER : Option A System.Exception Page 7

8 All exception derives from exception base class.exception can be generated programmatically or can be system.application Exception serves as the base class for all application specific exception classes. It derives from exception but does not provide any extended functionality. You should derive your custom application exception from Application Exception. Application exception is used when we want to define user defined exception,while system exception is all which is defined by.net. Q.19 Choose the correct output for given set of code: class Program static void Main(string[] args) try Console.WriteLine("csharp" + " " + 1/0); finally Console.WriteLine("Java"); Console.ReadLine(); A. csharp 0. B. Run time Exception generation. C. Compile time error. D. Java ANSWER : Option B Run time Exception generation Run time Error of division by zero. Q.20 Can I define my own exceptions? A. Yes. B. No. C. D. ANSWER : Option A Yes. just derive your exception class from Application.Exception. Page 8

9 Q.21 Is finally block mandatory with try catch blocks? A. Yes B. No C. D. ANSWER : Option B No No finally block is not mandatory with try catch blocks. Try Catch Finally However, The statements in the finally clause are guaranteed to execute following the execution of the try clause or the relevant catch clause. At first,the finally clause doesn^aeurtmt seem necessary.if you want code executed after try and catch,why cant you simply put it after the catch clause itself? The answer is simple : The try or catch clause could contain a return statement to return control to the calling method or to terminate the program. In that case the statement following the last catch clause of the try statement would not be executed. That^aEURTMs where the finally clause helps out. If the try or catch clause contains a return statement, the statement in the finally clause are guaranteed to execute regardless. Its also possible to exit a try or catch clause with a go to or a throw statement, which I will describe shortly. The statements in the finally clause execute in those cases as well. You generally use a finally clause for clean up.a finally clause might close a file,for example its possible to have clause following a try clause but with no catch clause. In this case,the user is notified of the error as if the program did not handle the exception, but the clause is executed before the program is terminated. Q.22 Exceptions is the Object-Oriented style of handling run-time errors. A. True. B. False. C. D. ANSWER : Option A True. Exception handling is an in built mechanism in.net framework to detect and handle run time errors. The.NET framework contains lots of standard exceptions. The exceptions are anomalies that occur during the execution of a program. They can be because of user, logic or system errors. If a user do not provide a mechanism to handle these Page 9

10 anomalies, the.net run time environment provide a default mechanism, which terminates the program execution. Q.23 What would be the output of following code snippet? Using System; Public class Throw Test2 Static int GetNumber(int index) Int[] nums = 300,600,900; If (index>nums.length) Throw new IndexOutOfRangeException(); Return nums[index]; Static void Main() Int result =GetNumber(4); A. 300 B. 600 C. 900 D. IndexOutOfRangeException ANSWER : Option D IndexOutOfRangeException Index passed to GetNumber Function is 4. However,maximum index which nums array can accept is 2. And we also have a check If(index >nums.length) Which means If(4 >3) So code will raise IndexOutofRangeException. Q.24 Which of the following statements is correct about an Exception? A. It occurs during compilation. B. It occurs during linking. C. It occurs at run-time. D. It occurs during Just-In-Time compilation. ANSWER : Option C It occurs at run-time. The runtime uses an exception-handling model based on exception objects and protected blocks of code. An Exception object is Page 10

11 created to represent an exception when it occurs. The runtime creates an exception information table for each executable. Each method of the executable has an associated array of exception-handling information (which can be empty) in the exception information table. Each entry in the array describes a protected block of code, any exception filters associated with that code, and any exception handlers (catch statements). This exception table is extremely efficient and does not cause any performance penalty in processor time or in memory use when an exception does not occur. You use resources only when an exception occurs. Q.25 Which of the following is the Object Oriented way of handling run-time errors? A. OnError B. HERESULT C. Exceptions D. Error codes ANSWER : Option C Exceptions When an exception occurs it firstly see by operating system.os return back it to CLR where CLR convert it to an object of that error then see if according to that exception is there any catch block which can handle that exception then OK otherwise terminates the application. Q.26 Which of these keywords must be used to monitor for exceptions? A. try B. finally C. throw D. catch ANSWER : Option A try The TRY statement takes no arguments. It is used to identify one or more Cach~A(c)MVBasic code statements between the TRY keyword and the CATCH keyword. This block of code is protected code for structured exception handling. If an exception occurs within this block of code, Cach~A(c) sets exception var to an object describing the exception, then transfers execution to an exception handler, identified by the CATCH statement. This is known as throwing an exception. If no exception occurs, execution continues with the next Cach~A(c)MVBasic statement after the END TRY statement. An exception may occur as a result of a runtime exception, such as attempting to divide by 0, or it may be explicitly Page 11

12 propagated by issuing a THROW statement. A TRY block must be immediately followed by a CATCH block. The paired TRY and CATCH are terminated by an END TRY statement. Page 12

#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

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

12/14/2016. Errors. Debugging and Error Handling. Run-Time Errors. Debugging in C# Debugging in C# (continued) 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

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

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

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

ECE 122. Engineering Problem Solving with Java

ECE 122. Engineering Problem Solving with Java ECE 122 Engineering Problem Solving with Java Lecture 24 Exceptions Overview Problem: Can we detect run-time errors and take corrective action? Try-catch Test for a variety of different program situations

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

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

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

Object Oriented Programming

Object Oriented Programming Object Oriented Programming Java lecture (10.1) Exception Handling 1 Outline Exception Handling Mechanisms Exception handling fundamentals Exception Types Uncaught exceptions Try and catch Multiple catch

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

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

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

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

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

Exceptions Questions https://www.journaldev.com/2167/java-exception-interview-questionsand-answers https://www.baeldung.com/java-exceptions-interview-questions https://javaconceptoftheday.com/java-exception-handling-interviewquestions-and-answers/

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

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

BBM 102 Introduction to Programming II Spring Exceptions

BBM 102 Introduction to Programming II Spring Exceptions BBM 102 Introduction to Programming II Spring 2018 Exceptions 1 Today What is an exception? What is exception handling? Keywords of exception handling try catch finally Throwing exceptions throw Custom

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

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

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

Introduction to Software Design

Introduction to Software Design CSI 1102 1 Abdulmotaleb El Saddik University of Ottawa School of Information Technology and Engineering (SITE) Multimedia Communications Research Laboratory (MCRLab) Distributed Collaborative Virtual Environments

More information

Data Structures. 02 Exception Handling

Data Structures. 02 Exception Handling David Drohan Data Structures 02 Exception Handling JAVA: An Introduction to Problem Solving & Programming, 6 th Ed. By Walter Savitch ISBN 0132162709 2012 Pearson Education, Inc., Upper Saddle River, NJ.

More information

Administration. Exceptions. Leftovers. Agenda. When Things Go Wrong. Handling Errors. CS 99 Summer 2000 Michael Clarkson Lecture 11

Administration. Exceptions. Leftovers. Agenda. When Things Go Wrong. Handling Errors. CS 99 Summer 2000 Michael Clarkson Lecture 11 Administration Exceptions CS 99 Summer 2000 Michael Clarkson Lecture 11 Lab 10 due tomorrow No lab tomorrow Work on final projects Remaining office hours Rick: today 2-3 Michael: Thursday 10-noon, Monday

More information

Software Exception Flow Analysis for WPF C# Asynchronous Programs Using Microsoft Visual Studio

Software Exception Flow Analysis for WPF C# Asynchronous Programs Using Microsoft Visual Studio Software Exception Flow Analysis for WPF C# Asynchronous Programs Using Microsoft Visual Studio Summary Recently, I was working on an implementation of a new software product feature based on asynchronous

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

EXCEPTION-HANDLING INTRIVIEW QUESTIONS

EXCEPTION-HANDLING INTRIVIEW QUESTIONS EXCEPTION-HANDLING INTRIVIEW QUESTIONS Q1.What is an Exception? Ans.An unwanted, unexpected event that disturbs normal flow of the program is called Exception.Example: FileNotFondException. Q2.What is

More information

Chapter 11 Handling Exceptions and Events. Chapter Objectives

Chapter 11 Handling Exceptions and Events. Chapter Objectives Chapter 11 Handling Exceptions and Events Chapter Objectives Learn what an exception is See how a try/catch block is used to handle exceptions Become aware of the hierarchy of exception classes Learn about

More information

Java Errors and Exceptions. Because Murphy s Law never fails

Java Errors and Exceptions. Because Murphy s Law never fails Java Errors and Exceptions Because Murphy s Law never fails 1 Java is the most distressing thing to hit computing since MS-DOS. Alan Kay 2 Corresponding Book Sections Pearson Custom Computer Science: Chapter

More information

EXCEPTION HANDLING. Summer 2018

EXCEPTION HANDLING. Summer 2018 EXCEPTION HANDLING Summer 2018 EXCEPTIONS An exception is an object that represents an error or exceptional event that has occurred. These events are usually errors that occur because the run-time environment

More information

CS313D: ADVANCED PROGRAMMING LANGUAGE

CS313D: ADVANCED PROGRAMMING LANGUAGE CS313D: ADVANCED PROGRAMMING LANGUAGE Computer Science department Lecture 6 : Abstraction Lecture Contents 2 Abstract classes Abstract methods Case study: Polymorphic processing Sealed methods & classes

More information

VB.NET MOCK TEST VB.NET MOCK TEST III

VB.NET MOCK TEST VB.NET MOCK TEST III http://www.tutorialspoint.com VB.NET MOCK TEST Copyright tutorialspoint.com This section presents you various set of Mock Tests related to VB.Net. You can download these sample mock tests at your local

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

C16b: Exception Handling

C16b: Exception Handling CISC 3120 C16b: Exception Handling Hui Chen Department of Computer & Information Science CUNY Brooklyn College 3/28/2018 CUNY Brooklyn College 1 Outline Exceptions Catch and handle exceptions (try/catch)

More information

Chapter 10. Exception Handling. Java Actually: A Comprehensive Primer in Programming

Chapter 10. Exception Handling. Java Actually: A Comprehensive Primer in Programming Chapter 10 Exception Handling Lecture slides for: Java Actually: A Comprehensive Primer in Programming Khalid Azim Mughal, Torill Hamre, Rolf W. Rasmussen Cengage Learning, 2008. ISBN: 978-1-844480-933-2

More information

6.Introducing Classes 9. Exceptions

6.Introducing Classes 9. Exceptions 6.Introducing Classes 9. Exceptions Sisoft Technologies Pvt Ltd SRC E7, Shipra Riviera Bazar, Gyan Khand-3, Indirapuram, Ghaziabad Website: www.sisoft.in Email:info@sisoft.in Phone: +91-9999-283-283 Learning

More information

Exceptions. Produced by. Introduction to the Java Programming Language. Eamonn de Leastar

Exceptions. Produced by. Introduction to the Java Programming Language. Eamonn de Leastar Exceptions Introduction to the Java Programming Language Produced by Eamonn de Leastar edeleastar@wit.ie Department of Computing, Maths & Physics Waterford Institute of Technology http://www.wit.ie http://elearning.wit.ie

More information

BBM 102 Introduction to Programming II Spring 2017

BBM 102 Introduction to Programming II Spring 2017 BBM 102 Introduction to Programming II Spring 2017 Exceptions Instructors: Ayça Tarhan, Fuat Akal, Gönenç Ercan, Vahid Garousi Today What is an exception? What is exception handling? Keywords of exception

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

COSC 123 Computer Creativity. I/O Streams and Exceptions. Dr. Ramon Lawrence University of British Columbia Okanagan

COSC 123 Computer Creativity. I/O Streams and Exceptions. Dr. Ramon Lawrence University of British Columbia Okanagan COSC 123 Computer Creativity I/O Streams and Exceptions Dr. Ramon Lawrence University of British Columbia Okanagan ramon.lawrence@ubc.ca Objectives Explain the purpose of exceptions. Examine the try-catch-finally

More information

14. Exception Handling

14. Exception Handling 14. Exception Handling 14.1 Intro to Exception Handling In a language without exception handling When an exception occurs, control goes to the operating system, where a message is displayed and the program

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

Advanced Flow of Control -- Introduction

Advanced Flow of Control -- Introduction Advanced Flow of Control -- Introduction Two additional mechanisms for controlling process execution are exceptions and threads Chapter 14 focuses on: exception processing catching and handling exceptions

More information

Topic 6: Exceptions. Exceptions are a Java mechanism for dealing with errors & unusual situations

Topic 6: Exceptions. Exceptions are a Java mechanism for dealing with errors & unusual situations Topic 6: Exceptions Exceptions are a Java mechanism for dealing with errors & unusual situations Goals: learn how to... think about different responses to errors write code that catches exceptions write

More information

A Third Look At Java. Chapter Seventeen Modern Programming Languages, 2nd ed. 1

A Third Look At Java. Chapter Seventeen Modern Programming Languages, 2nd ed. 1 A Third Look At Java Chapter Seventeen Modern Programming Languages, 2nd ed. 1 A Little Demo public class Test { public static void main(string[] args) { int i = Integer.parseInt(args[0]); int j = Integer.parseInt(args[1]);

More information

Exceptions, Case Study-Exception handling in C++.

Exceptions, Case Study-Exception handling in C++. PART III: Structuring of Computations- Structuring the computation, Expressions and statements, Conditional execution and iteration, Routines, Style issues: side effects and aliasing, Exceptions, Case

More information

Sri Vidya College of Engineering & Technology Question Bank

Sri Vidya College of Engineering & Technology Question Bank 1. What is exception? UNIT III EXCEPTION HANDLING AND I/O Part A Question Bank An exception is an event, which occurs during the execution of a program, that disrupts the normal flow of the program s instructions.

More information

Chapter 13 Exception Handling

Chapter 13 Exception Handling Chapter 13 Exception Handling 1 Motivations When a program runs into a runtime error, the program terminates abnormally. How can you handle the runtime error so that the program can continue to run or

More information

1. Find the output of following java program. class MainClass { public static void main (String arg[])

1. Find the output of following java program. class MainClass { public static void main (String arg[]) 1. Find the output of following java program. public static void main(string arg[]) int arr[][]=4,3,2,1; int i,j; for(i=1;i>-1;i--) for(j=1;j>-1;j--) System.out.print(arr[i][j]); 1234 The above java program

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

Exception Handling in C++

Exception Handling in C++ Exception Handling in C++ Professor Hugh C. Lauer CS-2303, System Programming Concepts (Slides include materials from The C Programming Language, 2 nd edition, by Kernighan and Ritchie, Absolute C++, by

More information

CS Internet programming Unit- I Part - A 1 Define Java. 2. What is a Class? 3. What is an Object? 4. What is an Instance?

CS Internet programming Unit- I Part - A 1 Define Java. 2. What is a Class? 3. What is an Object? 4. What is an Instance? CS6501 - Internet programming Unit- I Part - A 1 Define Java. Java is a programming language expressly designed for use in the distributed environment of the Internet. It was designed to have the "look

More information

G Programming Languages - Fall 2012

G Programming Languages - Fall 2012 G22.2110-003 Programming Languages - Fall 2012 Week 13 - Part 2 Thomas Wies New York University Review Last lecture Scala Outline Today: Exceptions Sources for today s lecture: PLP, ch. 8.5 Exceptions

More information

The University of Melbourne Department of Computer Science and Software Engineering Software Design Semester 2, 2003

The University of Melbourne Department of Computer Science and Software Engineering Software Design Semester 2, 2003 The University of Melbourne Department of Computer Science and Software Engineering 433-254 Software Design Semester 2, 2003 Answers for Tutorial 7 Week 8 1. What are exceptions and how are they handled

More information

COE318 Lecture Notes Week 10 (Nov 7, 2011)

COE318 Lecture Notes Week 10 (Nov 7, 2011) COE318 Software Systems Lecture Notes: Week 10 1 of 5 COE318 Lecture Notes Week 10 (Nov 7, 2011) Topics More about exceptions References Head First Java: Chapter 11 (Risky Behavior) The Java Tutorial:

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

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

Chapter 14. Exception Handling and Event Handling ISBN

Chapter 14. Exception Handling and Event Handling ISBN Chapter 14 Exception Handling and Event Handling ISBN 0-321-49362-1 Chapter 14 Topics Introduction to Exception Handling Exception Handling in Ada Exception Handling in C++ Exception Handling in Java Introduction

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

Internal Classes and Exceptions

Internal Classes and Exceptions Internal Classes and Exceptions Object Orientated Programming in Java Benjamin Kenwright Outline Exceptions and Internal Classes Why exception handling makes your code more manageable and reliable Today

More information

Fundamentals of Object Oriented Programming

Fundamentals of Object Oriented Programming INDIAN INSTITUTE OF TECHNOLOGY ROORKEE Fundamentals of Object Oriented Programming CSN- 103 Dr. R. Balasubramanian Associate Professor Department of Computer Science and Engineering Indian Institute of

More information

COMP200 EXCEPTIONS. OOP using Java, based on slides by Shayan Javed

COMP200 EXCEPTIONS. OOP using Java, based on slides by Shayan Javed 1 1 COMP200 EXCEPTIONS OOP using Java, based on slides by Shayan Javed Exception Handling 2 3 Errors Syntax Errors Logic Errors Runtime Errors 4 Syntax Errors Arise because language rules weren t followed.

More information

Object Oriented Programming

Object Oriented Programming Object Oriented Programming Java lecture (10.2) Exception Handling 1 Outline Throw Throws Finally 2 Throw we have only been catching exceptions that are thrown by the Java run-time system. However, it

More information

Understanding Structured Exception Handling

Understanding Structured Exception Handling Chapter 7 Understanding Structured Exception Handling In this chapter, you will learn how to handle runtime anomalies in your C# code through the use of structured exception handling. Not only will you

More information

COMP-202. Exceptions. COMP Exceptions, 2011 Jörg Kienzle and others

COMP-202. Exceptions. COMP Exceptions, 2011 Jörg Kienzle and others COMP-202 Exceptions Lecture Outline Exceptions Exception Handling The try-catch statement The try-catch-finally statement Exception propagation Checked Exceptions 2 Exceptions An exception is an object

More information

Exceptions. What exceptional things might our programs run in to?

Exceptions. What exceptional things might our programs run in to? Exceptions What exceptional things might our programs run in to? Exceptions do occur Whenever we deal with programs, we deal with computers and users. Whenever we deal with computers, we know things don

More information

CS 251 Intermediate Programming Exceptions

CS 251 Intermediate Programming Exceptions CS 251 Intermediate Programming Exceptions Brooke Chenoweth University of New Mexico Fall 2018 Expecting the Unexpected Most of the time our programs behave well, however sometimes unexpected things happen.

More information

Exception Handling: Control. Exception handling is the control of error conditions or other unusual events during the execution of a program.

Exception Handling: Control. Exception handling is the control of error conditions or other unusual events during the execution of a program. Exception Handling: Control Exception handling is the control of error conditions or other unusual events during the execution of a program. 1 In a language without exception handling: When an exception

More information

Exceptions. Examples of code which shows the syntax and all that

Exceptions. Examples of code which shows the syntax and all that Exceptions Examples of code which shows the syntax and all that When a method might cause a checked exception So the main difference between checked and unchecked exceptions was that the compiler forces

More information

More on Exception Handling

More on Exception Handling Chapter 18 More on Exception Handling Lecture slides for: Java Actually: A Comprehensive Primer in Programming Khalid Azim Mughal, Torill Hamre, Rolf W. Rasmussen Cengage Learning, 2008. ISBN: 978-1-844480-933-2

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

Exceptions Chapter 10. Instructor: Scott Kristjanson CMPT 125/125 SFU Burnaby, Fall 2013

Exceptions Chapter 10. Instructor: Scott Kristjanson CMPT 125/125 SFU Burnaby, Fall 2013 Exceptions Chapter 10 Instructor: Scott Kristjanson CMPT 125/125 SFU Burnaby, Fall 2013 2 Scope Exceptions: The purpose of exceptions Exception messages The call stack trace The try-catch statement Exception

More information

More on Exception Handling

More on Exception Handling Chapter 18 More on Exception Handling Lecture slides for: Java Actually: A Comprehensive Primer in Programming Khalid Azim Mughal, Torill Hamre, Rolf W. Rasmussen Cengage Learning, 2008. ISBN: 978-1-844480-933-2

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

COMP322 - Introduction to C++ Lecture 10 - Overloading Operators and Exceptions

COMP322 - Introduction to C++ Lecture 10 - Overloading Operators and Exceptions COMP322 - Introduction to C++ Lecture 10 - Overloading Operators and Exceptions Dan Pomerantz School of Computer Science 19 March 2012 Overloading operators in classes It is useful sometimes to define

More information

Atropos User s manual

Atropos User s manual Atropos User s manual Jan Lönnberg 22nd November 2010 1 Introduction Atropos is a visualisation tool intended to display information relevant to understanding the behaviour of concurrent Java programs,

More information

Learning to Program in Visual Basic 2005 Table of Contents

Learning to Program in Visual Basic 2005 Table of Contents Table of Contents INTRODUCTION...INTRO-1 Prerequisites...INTRO-2 Installing the Practice Files...INTRO-3 Software Requirements...INTRO-3 Installation...INTRO-3 Demonstration Applications...INTRO-3 About

More information

Exceptions. COMP 202 Exceptions. Exceptions. Exceptions. An exception is an object that describes an unusual or erroneous situation

Exceptions. COMP 202 Exceptions. Exceptions. Exceptions. An exception is an object that describes an unusual or erroneous situation COMP 202 CONTENTS: and Errors The try-catch statement The try-catch-finally statement Exception propagation An exception is an object that describes an unusual or erroneous situation division by zero reading

More information

Java Exceptions Version June 2009

Java Exceptions Version June 2009 Java Exceptions Version June 2009 Motivation Report errors, by delegating error handling to higher levels Callee might not know how to recover from an error Caller of a method can handle error in a more

More information

Chapter 14. Exception Handling and Event Handling

Chapter 14. Exception Handling and Event Handling Chapter 14 Exception Handling and Event Handling Chapter 14 Topics Introduction to Exception Handling Exception Handling in Ada Exception Handling in C++ Exception Handling in Java Introduction to Event

More information

Exception Handling. Chapter 9

Exception Handling. Chapter 9 Exception Handling Chapter 9 Objectives Describe the notion of exception handling React correctly when certain exceptions occur Use Java's exception-handling facilities effectively in classes and programs

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

CSC 1214: Object-Oriented Programming

CSC 1214: Object-Oriented Programming CSC 1214: Object-Oriented Programming J. Kizito Makerere University e-mail: jkizito@cis.mak.ac.ug www: http://serval.ug/~jona materials: http://serval.ug/~jona/materials/csc1214 e-learning environment:

More information

Chapter 12 Exception Handling

Chapter 12 Exception Handling Chapter 12 Exception Handling 1 Motivations Goal: Robust code. When a program runs into a runtime error, the program terminates abnormally. How can you handle the runtime error so that the program can

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

Exceptions (part 2) An exception is an object that describes an unusual or erroneous situation. Quick Review of Last Lecture.

Exceptions (part 2) An exception is an object that describes an unusual or erroneous situation. Quick Review of Last Lecture. (part 2) December 3, 2007 Quick Review of Last Lecture ComS 207: Programming I (in Java) Iowa State University, FALL 2007 Instructor: Alexander Stoytchev An exception is an object that describes an unusual

More information

VALLIAMMAI ENGINEERING COLLEGE

VALLIAMMAI ENGINEERING COLLEGE VALLIAMMAI ENGINEERING COLLEGE SRM Nagar, Kattankulathur 60 0 DEPARTMENT OF INFORMATION TECHNOLOGY QUESTION BANK III SEMESTER CS89- Object Oriented Programming Regulation 07 Academic Year 08 9 Prepared

More information

CMSC131. Exceptions and Exception Handling. When things go "wrong" in a program, what should happen.

CMSC131. Exceptions and Exception Handling. When things go wrong in a program, what should happen. CMSC131 Exceptions and Exception Handling When things go "wrong" in a program, what should happen. Go forward as if nothing is wrong? Try to handle what's going wrong? Pretend nothing bad happened? Crash

More information

AP COMPUTER SCIENCE JAVA CONCEPTS IV: RESERVED WORDS

AP COMPUTER SCIENCE JAVA CONCEPTS IV: RESERVED WORDS AP COMPUTER SCIENCE JAVA CONCEPTS IV: RESERVED WORDS PAUL L. BAILEY Abstract. This documents amalgamates various descriptions found on the internet, mostly from Oracle or Wikipedia. Very little of this

More information

Inheritance & Polymorphism

Inheritance & Polymorphism Inheritance & Polymorphism every class inherits from the Object class C# is a hierarchical object language multiple inheritance is not allowed instead, interfaces are used Equals GetHashCode GetType ToString

More information

Checked and Unchecked Exceptions in Java

Checked and Unchecked Exceptions in Java Checked and Unchecked Exceptions in Java Introduction In this article from my free Java 8 course, I will introduce you to Checked and Unchecked Exceptions in Java. Handling exceptions is the process by

More information

Exceptions, try - catch - finally, throws keyword. JAVA Standard Edition

Exceptions, try - catch - finally, throws keyword. JAVA Standard Edition Exceptions, try - catch - finally, throws keyword JAVA Standard Edition Java - Exceptions An exception (or exceptional event) is a problem that arises during the execution of a program. When an Exception

More information

CSCI 261 Computer Science II

CSCI 261 Computer Science II CSCI 261 Computer Science II Department of Mathematics and Computer Science Lecture 2 Exception Handling New Topic: Exceptions in Java You should now be familiar with: Advanced object-oriented design -

More information

What is the purpose of exceptions and exception handling? Vocabulary: throw/raise and catch/handle Exception propagation Java checked and unchecked

What is the purpose of exceptions and exception handling? Vocabulary: throw/raise and catch/handle Exception propagation Java checked and unchecked What is the purpose of exceptions and exception handling? Vocabulary: throw/raise and catch/handle Exception propagation Java checked and unchecked exceptions Java try statement Final wishes Java try-resource

More information

CS 3 Introduction to Software Engineering. 3: Exceptions

CS 3 Introduction to Software Engineering. 3: Exceptions CS 3 Introduction to Software Engineering 3: Exceptions Questions? 2 Objectives Last Time: Procedural Abstraction This Time: Procedural Abstraction II Focus on Exceptions. Starting Next Time: Data Abstraction

More information

Exceptions. Produced by. Algorithms. Eamonn de Leastar Department of Computing, Maths & Physics Waterford Institute of Technology

Exceptions. Produced by. Algorithms. Eamonn de Leastar Department of Computing, Maths & Physics Waterford Institute of Technology Exceptions Algorithms Produced by Eamonn de Leastar edeleastar@wit.ie Department of Computing, Maths & Physics Waterford Institute of Technology http://www.wit.ie http://elearning.wit.ie Exceptions ± Definition

More information

ASSERTIONS AND LOGGING

ASSERTIONS AND LOGGING SUMMARY Exception handling, ASSERTIONS AND LOGGING PROGRAMMAZIONE CONCORRENTE E DISTR. Università degli Studi di Padova Dipartimento di Matematica Corso di Laurea in Informatica, A.A. 2015 2016 rcardin@math.unipd.it

More information

Exception Handling. General idea Checked vs. unchecked exceptions Semantics of... Example from text: DataAnalyzer.

Exception Handling. General idea Checked vs. unchecked exceptions Semantics of... Example from text: DataAnalyzer. Exception Handling General idea Checked vs. unchecked exceptions Semantics of throws try-catch Example from text: DataAnalyzer Exceptions [Bono] 1 Announcements Lab this week is based on the textbook example

More information

DOWNLOAD PDF CORE JAVA APTITUDE QUESTIONS AND ANSWERS

DOWNLOAD PDF CORE JAVA APTITUDE QUESTIONS AND ANSWERS Chapter 1 : Chapter-wise Java Multiple Choice Questions and Answers Interview MCQs Java Programming questions and answers with explanation for interview, competitive examination and entrance test. Fully

More information