What is the use of throws keyword, JAVA Programming

Assignment Help:

What is the use of throws keyword ?

Rather than explicitly catching an exception you can declare in which your method throws the exception. This passes the repsonsibility to handle it to the method in which invokes your method. This is done with the throws keyword. For instance,
public static void copy(InputStream in, OutputStream out)
throws IOException {

byte[] buffer = new byte[256];
while (true) {
int bytesRead = in.read(buffer);
if (bytesRead == -1) break;
out.write(buffer, 0, bytesRead);
}

}
A single method may have the potential to throw more than one kind of exception. In this case the exception clases are just separated through commas. For example,
public BigDecimal divide(BigDecimal value, int roundingMode) throws ArithmeticException, IllegalArgumentException

You can declare in which your method throws runtime exceptions though you do not have to. The major use of this is as documentation for the programmer. It can also be useful in white box testing.

 


Related Discussions:- What is the use of throws keyword

Develop program using interactive brokers api, Develop Program using Intera...

Develop Program using Interactive Brokers API Project Description: We require a Matlab function using the Interactive Brokers API for real time trading with three arguments:

What does it mean that a method or class is abstract, What does it mean tha...

What does it mean that a method or class is abstract? An abstract class cannot be instantiated. Abstract methods may only be included in abstract classes. However, an abstract

What is messaging, Messaging is a method of communication among software co...

Messaging is a method of communication among software components or applications. A messaging system is a peer-to-peer facility: A messaging client can send messages to, and receiv

Program to store student record, Write a program called Grid. The program s...

Write a program called Grid. The program starts by prompting (asking) the user for the name of an input text file. This file is guaranteed to be correct and has the following fo

What is casting, What is casting? There are two types of casting, casti...

What is casting? There are two types of casting, casting among primitive numeric types and casting among object references. Casting among numeric types is used to convert large

Unicode-ascii utf16-utf 8, How many bits are we used in Unicode, ASCII, U...

How many bits are we used in Unicode, ASCII, UTF-16, and UTF-8 characters?

Difference between a scrollbar and a scrollpanel in jsp, A Scrollbar is a C...

A Scrollbar is a Component while Scroll Panel is a Container. A Scroll Panel handles its own events and performs its own scrolling.

Android apk for 3g dongles support, ANDROID APK for 3G dongles support P...

ANDROID APK for 3G dongles support Project Description: We want someone who will modify this Android app or code a similar one. The App function is to let Android tablet P

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd