Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > C# and C > C++ and Visual C++ > BOOK: Professional C++
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Professional C++
This is the forum to discuss the Wrox book Professional C++ by Nicholas A. Solter, Scott J. Kleper; ISBN: 9780764574849
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Professional C++ section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old December 4th, 2014, 06:26 PM
Registered User
Points: 5, Level: 1
Points: 5, Level: 1 Points: 5, Level: 1 Points: 5, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Dec 2014
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default java does not require exception be caught or declared

In the 2nd edition: some comments about java appear to be incorrect:
e.g.
"This behavior is different from that in other languages, such as Java, which requires a function or method to catch exceptions or declare them in their own function or method throw lists."
That's misleading because the third option, commonly employed in java is to use unchecked exceptions. Unchecked exceptions in java behave the same as C++ exceptions.

Here is an example demonstrating that catching/declaring exceptions is optional:
public class testException {
static Integer myValueOf(String s) throws NumberFormatException {
return Integer.valueOf(s);
}
public static void main(String[] args) {
try {
myValueOf("bad int1");
} catch (NumberFormatException e) {
System.out.println("int1");
}
myValueOf("bad int2");
}
}
Output:
int1
Exception in thread "main" java.lang.NumberFormatException: For input string: "bad int2"
at java.lang.NumberFormatException.forInputString(Unk nown Source)
at java.lang.Integer.parseInt(Unknown Source)
at java.lang.Integer.valueOf(Unknown Source)
at testException.myValueOf(testException.java:3)
at testException.main(testException.java:11)

The compiler does not require the exception thrown by method call myValueOf("bad int2"); to be caught, nor declare it in the function throw list.

To contrast two languages based on a feature that behaves the same way makes no sense.

Last edited by murray hughes; December 4th, 2014 at 06:28 PM. Reason: fixed mistake in title
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
exception is never thrown in body of try statement annumol Pro Java 1 February 11th, 2008 05:53 AM
Database does not update, no exception thrown hexOffender VB Databases Basics 5 November 24th, 2006 02:28 PM
Exception has been thrown by the target of an invo rajasarkar ASP.NET 1.0 and 1.1 Professional 2 June 19th, 2006 03:19 AM
Autosuggest Exception thrown jellie BOOK: Professional Ajax ISBN: 978-0-471-77778-6 3 March 14th, 2006 09:19 AM
Exception thrown Invalid_Viewstate r_ganesh76 ASP.NET 1.0 and 1.1 Professional 1 December 2nd, 2005 03:32 PM



All times are GMT -4. The time now is 07:46 AM.


Powered by vBulletin®
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.