{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

q6 - Programming Fundamentals for CIS Majors(CIS-3023 Quiz...

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

View Full Document Right Arrow Icon
Image of page 1

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

View Full Document Right Arrow Icon
Image of page 2
Image of page 3

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

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

Unformatted text preview: Programming Fundamentals for CIS Majors (CIS-3023) Quiz 6: 14th July 2010 Exception Handling in Java Answer the following questions: . Java exceptions are objects, and so you must use new to create an exception. True or False? The class is the superclass of all classes that are used to communicate both exceptions and errors between different functions and objects within a process It contains the basic functions that manipulate the messages and stack traces associated with exceptions and errors. What is the difference between Exception and Error in java? True or False? Enforced by the Java compiler and virtual machine, a checked exception indicates that a called function has failed to fulfill its end of the contract and forces programmers to deal with the exception that may be thrown. However, an unchecked exception is thrown because the calling function did not fulfill its end of the contract by passing bad or invalid data. They do not have to be necessarily caught or declared thrown. The types of exceptions that must be included in a method’s throws list if that method can generate one of these exceptions and does not handle it itself (using catch) are called Exceptions. IOException is an example of such an exception. What are the four constructors available in the Exception class? (Give their signatures). Class Not Found . Run Tlrne IIIe al A. un1ent xcep 'on IIIe al A un1ent xcep 'on Number Format Exception Index But of Bound Exception Index Array out of String Index out of Bounds Exception Bounds Exception 7. Refer to the basic Java Exception AP] hierarchy above. Now answer the following question: Classes Error and RunTimeException and their subclasses belong to Exceptions, while subclasses of Exception (other than the RuntimeException hierarchy) belong to Exceptions. 8. Is it possible to have a catch block without a corresponding try block? If so, when? 9. In addition to try-catch blocks, all the code that should always be executed (like closing buffers, dereferencing objects, double-checking data integrity, etc.) should be placed in the block. 10. (a) Does the order of placing catch statements matter in the catch block? (b) Consider the following code. try { } catch (Exception e) { } catch (ArithmeticException a) { } Is there anything wrong with this exception handler as written? Will this code compile? 11. Can a method define multiple exceptions to be thrown using the throws clause? If so, how? 12. The finally block is executed even when an exception is thrown and no catch matches the exception type. True or False? 13. Consider the following program: public class TestException { public static void main(String args) { String str = null; int len = str.length( ); The code compiles fine. However during execution, I got the following output: Exception in thread main java lang NullPointerException at TestException.main(TestException. j ava:4) Answer the following questions: (a) Where is the exception occurring in the program (which method raises it?)? (b) Why is the exception being raised? (0) Is this a checked or an unchecked exception? Why do you think so? 14. (a) What is the role of “model” in Model-View-Controller (MVC) software architectural pattern — providing the user interface or the domain logic or interface manipulation logic? (b) In distributed computing, the Client/ Server model provides a convenient way to interconnect programs that are distributed efficiently across different locations. In this model, the makes a service request to the , which fulfills the request. 15. Consider the following driver code. It requires a custom exception class. Add this class to indicate the following message “Your logic is flawed!” during the exception. public class TestJediLogic { public static void main(String args) throws JediLogicEx { boolean logic = false; if (! logic) { throw new JediLogicEx (); } else { System.out println("Live long and prosper!"); } ...
View Full Document

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern