wa4 - ECE 462 Written Assignment 3 Due: 12:20PM, November...

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon
ECE 462 Written Assignment 3 Due: 12:20PM, November 15, 2010 Name: PUID: 1 Exception Handling (outcome 7) Which statement is correct? A. In Java, a function may throw at most one type of exception. B. In Java, an integer can be passed when an exception is thrown. C. In C++, a function that may throw an exception must not call another function that may throw a different type of exception. D. An exception must be caught by the immediate caller; otherwise the program terminates. E. In Java, if an exception is not handled, the program terminates. 2 Java Exception (outcome 7) What is the output of this program? import java.io. * ; class Err extends Exception { } class outcome621 { public static void main( String[] args ) { try { f(0); } catch( Err e ) { System.out.println( "Exception caught" ); } } static void f(int j) throws Err { System.out.println( j ); if (j == 3) throw new Err(); 1
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
f( ++j ); } } 3 try - catch (outcome 7) Which statement is correct? A. In C++, the code inside finally is always executed regardless whether an exception has occurred. B. The same function may throw different types of exceptions. C. The code inside catch cannot throw any exception. D. In Java, each try has one and only one correspoding catch . E. If a function does not throw any exception, this function cannot be called inside a try block. 4 Java Exception Class (outcome 7) Please write the class of Exception74 . class Exception641 // >>>>> // fill the code for this class // <<<<< class outcome641 { static void f( ) throws Exception641 { throw new Exception641("thrown by f" ); } public static void main( String[] args ) { try { f(); } catch( Exception641 exp ) { System.out.println( exp.getMessage() ); // output: // thrown by f } } } 2
Background image of page 2
5 Catch C++ Exception (outcome 7) Please write the code so that the caller can catch the two types of exceptions. #include <iostream> #include <string> using namespace std; class ExceptionType1 { private: string et1_message; public: ExceptionType1(string m): et1_message(m) { } string getMessage() const { return et1_message; } }; class ExceptionType2 { private:
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 02/19/2012 for the course ECE 462 taught by Professor Samuelmidkiff during the Fall '11 term at Purdue University.

Page1 / 11

wa4 - ECE 462 Written Assignment 3 Due: 12:20PM, November...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online