0% found this document useful (0 votes)
13 views75 pages

VIPS OOPS Unit 2 Exception Handling

The document provides an overview of Java exceptions, explaining what they are, their hierarchy, and the various types, including checked and unchecked exceptions. It discusses the keywords used for exception handling in Java, such as try, catch, and finally, along with examples of how to implement these concepts in code. Additionally, it outlines the differences between exceptions and errors, as well as best practices for handling exceptions in Java programming.

Uploaded by

manvipaulemail
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views75 pages

VIPS OOPS Unit 2 Exception Handling

The document provides an overview of Java exceptions, explaining what they are, their hierarchy, and the various types, including checked and unchecked exceptions. It discusses the keywords used for exception handling in Java, such as try, catch, and finally, along with examples of how to implement these concepts in code. Additionally, it outlines the differences between exceptions and errors, as well as best practices for handling exceptions in Java programming.

Uploaded by

manvipaulemail
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 75

Course :

Paper Code:AIDS 202, IIOT202,AIML


Faculty : Dr. Shivanka
Assistant Professor
VIPS
What are Java Exception?

• Exception is an unwanted or unexpected event, which occurs during


the execution of a program, i.e. at run time, that disrupts the normal
flow of the program’s instructions. Exceptions can be caught and
handled by the program. When an exception occurs within a method, it
creates an object. This object is called the exception object. It contains
information about the exception, such as the name and description of
the exception and the state of the program when the exception
occurred.
Java Exceptions

What is an Exception?
§ An exception is an event that occurs during the execution of a program
that disrupts the normal flow of instructions.
§ When an error occurs, Java will normally stop and generate an error
message. The technical term for this is: Java will throw an exception
(throw an error).
§ When executing Java code, different errors can occur: coding errors
made by the programmer, errors due to wrong input, or other
unforeseeable things.
Exception Hierarchy

• All exception and error types are subclasses of class Throwable, which
is the base class of the hierarchy. One branch is headed by Exception.
This class is used for exceptional conditions that user programs should
catch. NullPointerException is an example of such an exception
Exception Hierarchy
Types of Exceptions

• Java defines several types of


exceptions that relate to its
various class libraries. Java also
allows users to define their own
exceptions.
Five Key words of Exceptional handling
• Java exception handling is managed via five keywords: try, catch, throw, throws, and finally.
Java try and catch
The try statement allows you to define a block of code to be tested for errors while it is being executed.
The catch statement allows you to define a block of code to be executed, if an error occurs in the try block.
The come in pairs:
Syntax
try {
// Block of code to try
}
catch(Exception e) {
// Block of code to handle errors
}
Built-in Exceptions:
• Built-in exceptions are the exceptions that are available in Java
libraries. These exceptions are suitable to explain certain error
situations.
• Checked Exceptions: Checked exceptions are called compile-time
exceptions because these exceptions are checked at compile-time by
the compiler.

• Unchecked Exceptions: The unchecked exceptions are just opposite


to the checked exceptions. The compiler will not check these
exceptions at compile time. In simple words, if a program throws an
unchecked exception, and even if we didn’t handle or declare it, the
program would not give a compilation error.
You learned that there are three categories of
errors: Syntax errors, Runtime errors, and Logic
errors.
Syntax errors arise because the rules of the
language have not been followed. They are
detected by the compiler.
Runtime errors occur while the program is running
if the environment detects an operation that is
impossible to carry out.
occur when a program doesn't
perform the way it was intended to.
Ø Gradually, programmers began to realize that the
traditional method of handling errors was too
cumbersome for most error handling situations.
Ø This gave rise to the Exception concept
ü When an error occurs, that represents an Exceptional condition.
ü cause the current program flow to be interrupted and
transferred to a registered exception handling block.
ü This might involve unrolling the method calling stack.

Ø involves a well-structured goto.


Definition of Error

Error is an unexpected event that cannot be handled at runtime. Errors can terminate your
program. Most of the time, programs cannot recover from an error. Errors cannot be caught or
handled. They are generally caused by the environment in which the code is running. e.g, The
image below is seen by almost all the computer users.
Definition of Exception

An Exception is the occurrence of an event that can disrupt the normal flow of the program instructions.
Exceptions can be caught and handled in order to keep the program working for the exceptional situation as
well, instead of halting the program flow.If the exception is not handled, then it can result in the termination
of the program. Exceptions can be used to indicate that an error has occurred in the program.

When an exception occurs, it creates an exception object. It holds information about the name and
description of the exception and stores the program's state when the exception occurred.

The below image shows the flow of an exception. definition of exception


Ø When an error is detected, an exception is thrown.
Ø Any exception which is thrown, must be caught by and exception
handler
ü If the programmer hasn't provided one, the exception will be caught by a
catch-all exception handler provided by the system.
ü The default exception handler may terminate the application.

Ø Exceptions can be rethrown if the exception cannot be handled by


the block which caught the exception
Ø Java has 5 keywords for exception handling:
try
catch
finally
throw
throws
ØExceptions break the normal flow of control.
ØWhen an exception occurs, the statement that would
normally execute next is not executed.
ØWhat happens instead depends on:
üwhether the exception is caught,
üwhere it is caught,
üwhat statements are executed in the ‘catch block’,
üand whether you have a ‘finally block’.
Major reasons why an exception Occurs

vInvalid user input


vDevice failure
vLoss of network connection
vPhysical limitations (out of disk memory)
vCode errors
vOpening an unavailable file
• Errors represent irrecoverable conditions such as Java virtual machine (JVM)
running out of memory, memory leaks, stack overflow errors, library
incompatibility, infinite recursion, etc. Errors are usually beyond the control of
the programmer, and we should not try to handle errors.
Example: Array out of bound Exception

Consider the following example:


If an error occurs, we can use
This will generate an error, because myNumbers[10]
does not exist. try...catch to catch the error and
public class Main { execute some code to handle it:
public static void main(String[ ] args) {
int[] myNumbers = {1, 2, 3};
System.out.println(myNumbers[10]); // error!
}}The output will be something like this:

Exception in thread "main"


java.lang.ArrayIndexOutOfBoundsException: 10
at Main.main(Main.java:4)
Example to use try...catch
Example
• The output will be:
public class Main {
public static void main(String[ ] args) {
try { • Something went wrong.
int[] myNumbers = {1, 2, 3};
System.out.println(myNumbers[10]);
} catch (Exception e) {
System.out.println("Something went wrong.");
}
}
}
Finally Keyword

The finally statement lets you execute code, after try...catch,


regardless of the result: • The output will be:
Example
public class Main { • Something went wrong.
public static void main(String[] args) {
try {
• The 'try catch' is finished.
int[] myNumbers = {1, 2, 3};
System.out.println(myNumbers[10]);
} catch (Exception e) {
System.out.println("Something went wrong.");
} finally {
System.out.println("The 'try catch' is finished.");
} }}
1 import java.util.Scanner;
2
3 public class ExceptionDemo {
4 public static void main(String[] args) {
5 Scanner scanner = new Scanner(System.in);
6 System.out.print("Enter an integer: ");
7 int number = scanner.nextInt();
8 If anexceptionoccurs onthis
9 line, therest of the lines inthe // Display the result
methodareskippedandthe System.out.println(
10
programis terminated.
11 "The number entered is " + number);
12 }
13 }
Terminated.
Example to use try...catch

To illustrate how easily this can be done, the following program includes a try block and a catch clause that processes the
ArithmeticException generated by the division-by-zero error:
class Exc2 {
public static void main(String args[]) {
int d, a; Output:
try { // monitor a block of code. This program generates the
following output:
d = 0;
a = 42 / d; Division by zero.
System.out.println("This will not be printed.");
} catch (ArithmeticException e) { // catch divide-by-zero error After catch statement
System.out.println("Division by zero.");
}
System.out.println("After catch statement.");
}}
1. Prevent the exception from happening.
2. Catch it in the method in which it occurs, and either
a. Fix up the problem and resume normal execution.
b. Rethrow it.
c. Throw a different exception.
3. Declare that the method throws the exception.
4. With 1. and 2.a. the caller never knows there was an
error.
5. With 2.b., 2.c., and 3., if the caller does not handle the
exception, the program will terminate and display a
stack trace.
try
{
// Code which might throw an exception
// ...
}
catch(FileNotFoundException x)
{
// code to handle a FileNotFound exception
}
catch(IOException x)
{
// code to handle any other I/O exceptions
}
catch(Exception x)
{
// Code to catch any other type of exception
}
finally
{
// This code is ALWAYS executed whether an exception was thrown
// or not. A good place to put clean-up code. ie. close
// any open files, etc...
}
• For normal execution:
• try block executes, then finally block executes, then other statements
execute
• When an error is caught and the catch block throws an exception or returns:
• try block is interrupted
• catch block executes (until throw or return statement)
• finally block executes
• When error is caught and catch block doesn’t throw an exception or return:
• try block is interrupted
• catch block executes
• finally block executes
• other statements execute
• When an error occurs that is not caught:
• try block is interrupted
• finally block executes
Preceding step

try block

throw
statement

unmatched catch

matching catch

unmatched catch

next step
Preceding step

try block

throw
statement

unmatched catch

matching catch

unmatched catch

next step
Preceding step

try block

throw
statement

unmatched catch

matching catch

unmatched catch

finally

next step
Exception
"thrown" here
Thrown exception matched against
first set of exception handlers

Exception
handler
If it fails to match, it is matched against
next set of handlers, etc.
Exception
handler
If exception matches none of handlers,
program is abandoned
Suppose no
exceptions in the
statements
try {
statements;
}
catch(TheException ex) {
handling ex;
}
finally {
finalStatements;
}

Next statement;
The final block is
try { always executed
statements;
}
catch(TheException ex) {
handling ex;
}
finally {
finalStatements;
}

Next statement;
Next statement in the
try { method is executed
statements;
}
catch(TheException ex) {
handling ex;
}
finally {
finalStatements;
}

Next statement;
try { Suppose an exception
statement1; of type Exception1 is
statement2; thrown in statement2
statement3;
}
catch(Exception1 ex) {
handling ex;
}
finally {
finalStatements;
}

Next statement;
try { The exception is
statement1; handled.
statement2;
statement3;
}
catch(Exception1 ex) {
handling ex;
}
finally {
finalStatements;
}

Next statement;
try { The final block is
statement1; always executed.
statement2;
statement3;
}
catch(Exception1 ex) {
handling ex;
}
finally {
finalStatements;
}

Next statement;
try { The next statement in
statement1; the method is now
statement2; executed.
statement3;
}
catch(Exception1 ex) {
handling ex;
}
finally {
finalStatements;
}

Next statement;
try {
statement1; statement2 throws an
statement2; exception of type
statement3; Exception2.
}
catch(Exception1 ex) {
handling ex;
}
catch(Exception2 ex) {
handling ex;
throw ex;
}
finally {
finalStatements;
}

Next statement;
try {
statement1; Handling exception
statement2;
statement3;
}
catch(Exception1 ex) {
handling ex;
}
catch(Exception2 ex) {
handling ex;
throw ex;
}
finally {
finalStatements;
}

Next statement;
try {
statement1; Rethrow the exception
statement2; and control is
statement3; transferred to the caller
}
catch(Exception1 ex) {
handling ex;
}
catch(Exception2 ex) {
handling ex;
throw ex;
}
finally {
finalStatements;
}

Next statement;
Trace a Program Execution
try {
statement1; Execute the final block
statement2;
statement3;
}
catch(Exception1 ex) {
handling ex;
}
catch(Exception2 ex) {
handling ex;
throw ex;
}
finally {
finalStatements;
}

Next statement;
method1() { declare exception
method2() throws Exception {
try {
invoke method2; if (an error occurs) {
}
catchexception catch (Exception ex) { throw new Exception(); throwexception
Process exception; }
} }
}
Every method must state the types of checked exceptions
it might throw. This is known as declaring exceptions.

public void myMethod() throws IOException

public void myMethod() throws IOException,

OtherException
If your method is defined to throw an exception, you need not
catch it within your method

public void addURL(String urlText) throws MalformedURLException


{
URL aURL = new URL(urlText);

// if the above throws a MalformedURLException, we need not have


// a try/catch block here because the method is defined to
// throw that exception. Any method calling this method MUST
// have a try/catch block which catches MalformedURLExceptions.
// Control is automatically transferred to that catch block.

}
If you don’t want the exception to be handled in the same function you can use the
throws class to handle the exception in the calling function.

public class myexception{


public static void main(String args[])
In this example, the main
{
method calls the
try{
checkEx() method and the
checkEx(); checkEx method tries to
} catch(FileNotFoundException ex){ } open a file, If the file in not
} available, then an
public void checkEx() throws FileNotFoundException exception is raised and
{ passed to the main
File f = new File(“myfile”); method, where it is
FileInputStream fis = new FileInputStream(f); handled.
//continue processing here.
}
}
Ø A Method can throw multiple exceptions.
Ø Multiple exceptions are separated by commas after the throws
publickeyword:
class MyClass
{
public int computeFileSize() throws IOException, ArithmeticException
[...]

public void method1()


{
MyClass anObject = new MyClass();
try
{
int theSize = anObject.computeFileSize();
}
catch(ArithmeticException x)
{
// ...
}
catch(IOException x)
{
// ...
ü Since all Exception classes are a subclass of the Exception class,
a catch handler which catches "Exception" will catch all exceptions.
ü It must be the last in the catch List
public void method1()
{
FileInputStream aFile;
try
{
aFile = new FileInputStream(...);
int aChar = aFile.read();
//...
}
catch(IOException x)
{
// ...
}
catch(Exception x)
{
// Catch All Exceptions
public void method1()
{
FileInputStream aFile;
try
{
aFile = new FileInputStream(...);
int aChar = aFile.read();
//...
}
catch(IOException x)
{
// ...
}
catch(Exception x)
{
// Catch All other Exceptions
}
finally
{
try
{
aFile.close();
}
catch (IOException x)
{
// close might throw an exception
}
}
Java throw keyword
• The flow of execution stops immediately after the throw statement; any subsequent statements are
not executed. The nearest enclosing try block is inspected to see if it has a catch statement that
matches the type of exception. If it does find a match, control is transferred to that statement. If not,
then the next enclosing try statement is inspected, and so on. If no matching catch is found, then
the default exception handler halts the programand prints the stack trace.
• The Java throw keyword is used to throw an exception explicitly.

• We specify the exception object which is to be thrown. The Exception has some message with it
that provides the error description. These exceptions may be related to user inputs, server, etc.

• We can throw either checked or unchecked exceptions in Java by throw keyword. It is mainly used
to throw a custom exception.
Demonstrate throw Example
This program gets two chances to deal with the same error. First, main( ) sets up an exception
context and then calls demoproc( ). The demoproc( ) method then sets up another exception_x0002_handling
context and immediately throws a new instance of NullPointerException, which is is caught on the next line.
The exception is then rethrown.
class ThrowDemo {
public static void main(String
static void demoproc() {
args[]) {
try {
throw new try {
NullPointerException("demo");
demoproc();
} catch(NullPointerException e) {
System.out.println("Caught inside } catch(NullPointerException e) {
demoproc."); System.out.println("Recaught: " +
throw e; // rethrow the exception e);
}} Resulting output:
Caught inside demoproc.
}}}
Recaught:
java.lang.NullPointerException: demo
Throw incorrect example
// This program contains an error and will not To make this example compile,
compile.
you need to make two changes.
class ThrowsDemo {
static void throwOne() { First, you need to declare
System.out.println("Inside throwOne."); that throwOne( ) throws
throw new IllegalAccessException("demo"); IllegalAccessException.
} Second, main( ) must define a
public static void main(String args[]) { try/catch
throwOne();
statement that catches this
}
exception.
}
Throws corrected example
The corrected example is shown public static void main(String args[]) {
here: try {
// This is now correct. throwOne();

class ThrowsDemo { } catch (IllegalAccessException e) {


System.out.println("Caught " + e);
static void throwOne() throws
IllegalAccessException { }}}
Output:
System.out.println("Inside
throwOne.");
Here is the output generated by running this example
throw new program:
IllegalAccessException("demo"); inside throwOne
} caught java.lang.IllegalAccessException: demo
q You can throw exceptions from your own methods.

q To throw an exception, create an instance of the exception class


and "throw" it.
q If you throw checked exceptions, you must indicate which
exceptions your method throws by using the throws keyword
public void withdraw(float anAmount) throws InsufficientFundsException
{
if (anAmount<0.0)
throw new IllegalArgumentException("Cannot withdraw negative amt");

if (anAmount>balance)
throw new InsuffientFundsException("Not enough cash");

balance = balance - anAmount;


}
Ø If you catch an exception but the code determines it cannot
reasonably handle the exception, it can be rethrown:

public void addURL(String urlText) throws MalformedURLException


{
try
{
URL aURL = new URL(urlText);
// ...
}
catch(MalformedURLException x)
{
// determine that the exception cannot be handled here
throw x;
}
}
/** Set a new radius */
public void setRadius(double newRadius)
{
if (newRadius >= 0)
radius = newRadius;
else
throw new IllegalArgumentException(
"Radius cannot be negative");
}
An exception occurs in a method. If you want
the exception to be processed by its caller, you
should create an exception object and throw it.
If you can handle the exception in the method
where it occurs, there is no need to throw it.
main method { method1 { method2 { An exception
... ... ... is thrown in
try { try { try { method3
... ... ...
invoke method1; invoke method2; invoke method3;
statement1; statement3; statement5;
} } }
catch (Exception1 ex1) { catch (Exception2 ex2) { catch (Exception3 ex3) {
Process ex1; Process ex2; Process ex3;
} } }
statement2; statement4; statement6;
} } }
ClassNotFoundException

IOException
ArithmeticException
Exception AWTException
NullPointerException
RuntimeException
IndexOutOfBoundsException
Object Throwable Several more classes
IllegalArgumentException

LinkageError Several more classes

VirtualMachineError
Error
AWTError

Several more classes


ClassNotFoundException

IOException
System errors are thrown by JVM
ArithmeticException
Exception AWTException and represented in the Error class.
The Error class describes internal
NullPointerException
RuntimeException
system errors. Such errors rarely
IndexOutOfBoundsException
Object Throwable Several more classes occur. If one does, there is little you
canIllegalArgumentException
do beyond notifying the user and
LinkageError trying toclasses
Several more terminate the program
gracefully.
VirtualMachineError
Error
AWTError

Several more classes


ClassNotFoundException

IOException
ArithmeticException
Exception AWTException
NullPointerException
RuntimeException
IndexOutOfBoundsException
Object Throwable Several more classes
IllegalArgumentException

LinkageError Several more classes

Exception describes errors caused by your program


and external circumstances. These errors can be
VirtualMachineError
Error
caught and handled by your program.
AWTError

Several more classes


ClassNotFoundException

IOException
ArithmeticException
Exception AWTException
NullPointerException
RuntimeException
IndexOutOfBoundsException
Object Throwable Several more classes
IllegalArgumentException

LinkageError Several more classes

RuntimeException is caused by programming errors,


VirtualMachineError

such as bad casting,


Error accessing an out-of-bounds array,

and numeric errors. AWTError

Several more classes


RuntimeException, Error and their
subclasses are known as unchecked
exceptions. All other exceptions are
known as checked exceptions, meaning
that the compiler forces the programmer
to check and deal with the exceptions.
Java forces you to deal with checked exceptions. If a method declares a
c h e c ke d exc e pt i o n (i . e . , a n exc e pt i o n o t h e r t h a n E r ro r o r
RuntimeException), you must invoke it in a try-catch block or declare to
throw the exception in the calling method. For example, suppose that
method p1 invokes method p2 and p2 may throw a checked exception (e.g.,
IOException), you have to write the code as shown in (a) or (b).

void p1() { void p1() throws IOException {


try {
p2(); p2();
}
catch (IOException ex) { }
...
}
}

(a) (b)
In most cases, unchecked exceptions reflect programming
logic errors that are not recoverable. For example, a
NullPointerException is thrown if you access an object
through a reference variable before an object is assigned to
it; an IndexOutOfBoundsException is thrown if you access
an element in an array outside the bounds of the array.
These are the logic errors that should be corrected in the
program. Unchecked exceptions can occur anywhere in the
program. To avoid cumbersome overuse of try-catch
blocks, Java does not mandate you to write code to catch
unchecked exceptions.
Java Catch Multiple Exceptions
Java Multi-catch block
A try block can be followed by one or more catch blocks. Each catch
block must contain a different exception handler. So, if you have to
perform different tasks at the occurrence of different exceptions, use java
multi-catch block.
Points to remember
At a time only one exception occurs and at a time only one catch block is
executed.
All catch blocks must be ordered from most specific to most general, i.e.
catch for ArithmeticException must come before catch for Exception.
Flowchart of Multi-catch Block
Multiple catch statements
/ Demonstrate multiple catch statements. catch(ArithmeticException e) {
class MultiCatch { System.out.println("Divide by 0: " + e);
public static void main(String args[]) { } catch(ArrayIndexOutOfBoundsException
try { e) {
int a = args.length; System.out.println("Array index oob: " + e);
System.out.println("a = " + a); }
int b = 42 / a;
Output: System.out.println("After try/catch blocks.");
int c[] = { 1 }; C:\>java MultiCatch }}
c[42] = 99; a=0
Divide by 0:
} java.lang.ArithmeticException:
/ by zero
After try/catch blocks.
Why use Custom Exceptions?
• Java exceptions cover almost all the general type of exceptions that
may occur in the programming. However, we sometimes need to
create custom exceptions.
• To catch and provide specific treatment to a subset of existing Java
exceptions.
• Business logic exceptions: These are the exceptions related to
business logic and workflow. It is useful for the application users or
the developers to understand the exact problem.
Custom Exception
• Consider the following example, where we create a custom exception
named WrongFileNameException:

public class WrongFileNameException extends Exception {

public WrongFileNameException(String errorMessage) {

super(errorMessage);
}
}
Custom Exception Example
/ This program creates a custom exception type. static void compute(int a) throws MyException {
System.out.println("Called compute(" + a + ")");
class MyException extends Exception {
if(a > 10) Output:
private int detail; This example Called compute(1)
throw new MyException(a);
MyException(int a) { defines a subclass Normal exit
of Exception System.out.println("Normal exit");
Called compute(20)
detail = a; called } Caught
} MyException. public static void main(String args[]) { MyException[20]
public String toString() { This subclass is try {
quite compute(1);
return "MyException[" + detail + "]";simple: it has
compute(20);
} only a
} catch (MyException e) {
constructor plus
}
an overloaded System.out.println("Caught " + e);
class ExceptionDemo { toString( ) }}
method that
displays the
Example 1:Custom Exception
Simple example of Java custom • A l s o t h e c o n s t r u c t o r o f
exception. In the following code, Exception class can be called
c o n s t r u c t o r o f without using a parameter and
InvalidAgeException takes a calling super() method is not
string as an argument. This string m a n d a t o r y .
is passed to constructor of parent
class Exception using the super() TestCustomException1.java
method.
Java Custom Exception
• In Java, we can create our own exceptions • Using the custom exception, we
that are derived classes of the Exception
class. Creating our own Exception is
can have your own exception
known as custom exception or user- and message. Here, we have
defined exception. Basically, Java custom passed a string to the constructor
exceptions are used to customize the of superclass i.e. Exception class
exception according to user need.
that can be obtained using
getMessage() method on the
• Consider the example 1 in which object we have created.
InvalidAgeException class extends the
Exception class.
Example Custom Exception
// throw an object of user defined exception
// class representing custom exception
throw new InvalidAgeException("age is not valid for vote"); }
class InvalidAgeException extends Exception
else {
{
System.out.println("welcome to vote");
public InvalidAgeException (String str)
} } // main method
{ public static void main(String args[])
// calling the constructor of parent Exception { try
super(str); { // calling the method
} } // class that uses custom exception InvalidAgeException validate(13); }

public class TestCustomException1 catch (InvalidAgeException ex)

{ // method to check the age { System.out.println("Caught the exception");


// printing the message from InvalidAgeException object
static void validate (int age) throws InvalidAgeException{
System.out.println("Exception occured: " + ex); }
if(age < 18){
System.out.println("rest of the code..."); } }
Output:

• Java Custom Exception


Example 2:Custom Exception
// class representing custom exception catch (MyCustomException ex)
class MyCustomException extends Exception
{
{ }
// class that uses custom exception MyCustomException System.out.println("Caught the
public class TestCustomException2
exception");
{
// main method System.out.println(ex.getMessage());
public static void main(String args[]) { }
try
System.out.println("rest of the code...");
{ // throw an object of user defined exception
throw new MyCustomException(); } }
} Output:

You might also like