Introduction to Java Programming and Data Structures, Comprehensive Version (11th Edition)
Introduction to Java Programming and Data Structures, Comprehensive Version (11th Edition)
11th Edition
ISBN: 9780134670942
Author: Y. Daniel Liang
Publisher: PEARSON
Question
Book Icon
Chapter 12.9, Problem 12.9.2CP
Program Plan Intro

Custom exception class:

The custom exception class is defined with help of extending the Exception class or subclass of Exception.

  • Java contains some exception classes. But if the program run into problem then create own exception class to handle that exception or problem which is derived from Exception class or subclass of Exception.
  • The syntax to declare the custom exception class is given below:

public class ClassName extends Exception

{

}

Blurred answer
Students have asked these similar questions
Let's revisit chapter 5 example, but this time, no method can throw any exception out of the method and if an exception was detected then you will have to throw your own custom exception to let the user know what happened.   public class Chapter11Demo{ public static void main(java.lang.String[] args) {method1();}private static void method1(){ method2();}private static void method2(){ method3();}private static void method3(){ method4();}private static void method4(){ method5();}private static void method5(){ method6();}private static void method6(){       java.io.File in=new java.io.File("somefile.txt");       java.io.File out=new java.io.File("somefile2.txt");       java.util.Scanner inFile=new java.util.Scanner(in);       java.io.FileWriter outFile=new java.io.FileWriter(out);    }}
Consider the following test method code fragment, which tests whether a method given invalid input produces the expected exception in response. On which of the following lines should the test return false, indicating that the test has failed? There may be more than one correct answer! try { methodCall(invalidInput); // 1. line after method call } catch (IllegalArgumentException e) { // 2. correct } catch (Exception e) { // 3. incorrect } Group of answer choices 1. line after method call 2. correct 3. incorrect
I. Output of public class Test implements Runnable { public void run() { System.out.println( "running!" ); } public void start( int i ) { } public static void main( String[] args ) { Test t = new Test(); Thread th = new Thread( t ); t.start( 1 ); } } II. Output of public static void main(String[] args) { int[] arr = { 0, 1, 2, 3, 4 }; System.out.println( arr[arr[arr.length-1]] ); } III. System.out.println (“3 in binary Nos=” + “Integer.toBinaryString(3)”); IV. Will the following java code compile? if not why? if yes write the output. abstract class A { abstract void callme(); // concrete methods are still allowed in abstract classes void callmetoo() { System.out.println("This is a concrete method."); } } class B extends A { void callmetoo() { System.out.println("B's implementation of callme."); } } class AbstractDemo { public static void main(String args[]) { B b = new B(); b.callmetoo(); } } } V.…

Chapter 12 Solutions

Introduction to Java Programming and Data Structures, Comprehensive Version (11th Edition)

Ch. 12.4 - Prob. 12.4.3CPCh. 12.4 - Prob. 12.4.4CPCh. 12.4 - Prob. 12.4.5CPCh. 12.4 - Prob. 12.4.6CPCh. 12.4 - What is displayed when running the following...Ch. 12.4 - Prob. 12.4.8CPCh. 12.4 - What does the method getMessage() do?Ch. 12.4 - What does the method printStackTrace() do?Ch. 12.4 - Prob. 12.4.11CPCh. 12.4 - Prob. 12.4.12CPCh. 12.5 - Prob. 12.5.1CPCh. 12.6 - Prob. 12.6.1CPCh. 12.7 - Prob. 12.7.1CPCh. 12.8 - Prob. 12.8.1CPCh. 12.9 - Prob. 12.9.1CPCh. 12.9 - Prob. 12.9.2CPCh. 12.10 - What is wrong about creating a File object using...Ch. 12.10 - How do you check whether a file already exists?...Ch. 12.10 - Can you use the File class for I/O? Does creating...Ch. 12.11 - Prob. 12.11.1CPCh. 12.11 - Prob. 12.11.2CPCh. 12.11 - Prob. 12.11.3CPCh. 12.11 - Prob. 12.11.4CPCh. 12.11 - What will happen if you attempt to create a...Ch. 12.11 - Prob. 12.11.6CPCh. 12.11 - Suppose you enter 45 57, 8 789, then press the...Ch. 12.11 - Prob. 12.11.8CPCh. 12.12 - How do you create a Scanner object for reading...Ch. 12.13 - Prob. 12.13.1CPCh. 12.13 - Simplify the code in lines 20-28 as follows: 1....Ch. 12 - Prob. 12.1PECh. 12 - (InputMismatchException) Write a program that...Ch. 12 - (ArrayIndexOutOfBoundsException) Write a program...Ch. 12 - (IllegalArgumentException) Modify the Loan class...Ch. 12 - (IllegalTriangleException) Programming Exercise...Ch. 12 - (NumberFormatException) Listing 6.8 implements the...Ch. 12 - Prob. 12.7PECh. 12 - Prob. 12.8PECh. 12 - Prob. 12.9PECh. 12 - Prob. 12.10PECh. 12 - Prob. 12.11PECh. 12 - (Reformat Java source code) Write a program that...Ch. 12 - (Count characters, words, and lines in a file)...Ch. 12 - (Process scores in a text file) Suppose a text...Ch. 12 - (Write/read data) Write a program to create a file...Ch. 12 - Prob. 12.16PECh. 12 - (Game: hangman) Rewrite Programming Exercise 7.35....Ch. 12 - Prob. 12.18PECh. 12 - (Count words) Write a program that counts the...Ch. 12 - Prob. 12.20PECh. 12 - (Data sorted?) Write a program that reads the...Ch. 12 - Prob. 12.22PECh. 12 - (Process scores in a text file on the Web) Suppose...Ch. 12 - (Create large dataset) Create a data file with...Ch. 12 - (Create a directory) Write a program that prompts...Ch. 12 - Prob. 12.26PECh. 12 - (Replace words) Suppose you have a lot of files in...Ch. 12 - (Rename files) Suppose you have a lot of files in...Ch. 12 - (Rename files) Suppose you have several files in a...Ch. 12 - (Occurrences of each letter) Write a program that...Ch. 12 - (Baby name popularity ranking) The popularity...Ch. 12 - (Ranking summary) Write a program that uses the...
Knowledge Booster
Background pattern image
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education