Wrox Programmer Forums
|
Java Basics General beginning Java language questions that don't fit in one of the more specific forums. Please specify what version.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Java Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 25th, 2010, 02:15 PM
Registered User
 
Join Date: Mar 2010
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Lightbulb throw/throws

What is the difference between the keywords throw and throws in exception handling?
 
Old March 25th, 2010, 09:31 PM
Friend of Wrox
 
Join Date: Dec 2008
Posts: 238
Thanks: 2
Thanked 20 Times in 19 Posts
Default

They are used in different portions of the code for different purposes:
  • throws: it declares that a method can potentially throw particular type or types of exception
  • throw: it actually throws the exception
 
Old April 27th, 2010, 09:43 AM
Registered User
 
Join Date: Apr 2010
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
Originally Posted by debasish View Post
What is the difference between the keywords throw and throws in exception handling?
The difference between throws and throw is that throw is used to define user defined exceptions as per their requirement where as throws is used to propagate the exception

ex:
public class Servlet extends HttpServlet(HttpServletRequest req,HttpServletResponse res)throws IOException,ServletException
{
//code
}





Similar Threads
Thread Thread Starter Forum Replies Last Post
throw an exception in catch Muyavil Java Basics 3 April 11th, 2009 10:56 PM
Dropdownlist throws exception abhishekkashyap27 C# 2005 2 January 14th, 2008 03:05 PM
Ch 2 pg 70: links throw error subgenius BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6 4 August 16th, 2004 05:26 PM
TRY CATCH THROW question savoym C# 1 July 1st, 2004 03:54 PM
how to pass multiple values throw url class object kfarooq Servlets 1 June 20th, 2003 04:06 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.