473,471 Members | 1,970 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

unchecked exception

5 New Member
why unchecked exception raise while run this program. if i tack it out (throws Exeception ) this code will work well .


Expand|Select|Wrap|Line Numbers
  1. interface Foldable {
  2.      public void fold() throws Exception ;
  3.  
  4. }
  5.  
  6.  
  7. class Paper implements Foldable {
  8.     public void fold() { 
  9.           System.out.print("Fold");
  10.         }
  11. }
  12.  
  13.  
  14. public class Tester {
  15.    public static void main(String args []) {
  16.           Foldable obj1 = new Paper();
  17.           obj1.fold(); 
  18.           Paper obj2 = new Paper(); 
  19.           obj2.fold();
  20.    }
  21. }
Jun 26 '11 #1
1 1844
Nepomuk
3,112 Recognized Expert Specialist
In short, every Exception has to be caught by a try-catch block or passed on to the next higher instance. This is true, even if there's just a possibility that an Exception might be thrown but never is.
So, if you change the main function to
Expand|Select|Wrap|Line Numbers
  1. try {
  2.    Foldable obj1 = new Paper();
  3.    obj1.fold(); 
  4.    Paper obj2 = new Paper(); 
  5.    obj2.fold();
  6. } catch (Exception e) {
  7.    System.err.println("Exception was thrown");
  8. }
then you shouldn't have any problems.

For more information, check out the article I wrote about exceptions.

Greetings,
Nepomuk
Jun 27 '11 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Steven Buroff | last post by:
I can't seem to get the @SuppressWarnings("unchecked") to work. Here is my test program. public class Tryit { @SuppressWarnings({"unchecked"}) public <T> T doit(Class<T> clazz){ T val =...
17
by: Bryan Bullard | last post by:
hi, is there a way to force the user of an object to catch exceptions of specific type? for instance a compile error is issued if exception 'ExeceptionXXX' thrown by method...
16
by: ChInKPoInt [No MCSD] | last post by:
I am using Visual Studio 2K3 writing a ASP.NET web application. Is there a way to force the C# compiler to catch possible exception? In Java, all exceptions thrown MUST BE caught, otherwise...
41
by: Stuart Golodetz | last post by:
Hi all, Just wondering whether there's any reason why exception specifications are enforced at runtime, rather than at compile-time like in Java? (This was prompted by reading an article on...
6
by: Bruce | last post by:
I have a reference assembly that I wrote. The assembly can throw exceptions. I am handling these exceptions but, when running my code from VB, VB still insists on setting a breakpoint where the...
3
dmjpro
by: dmjpro | last post by:
why java provides two flavour exceptions? why java tells programmer to handle or throw anyway some exceptions and some not? as jvm can catch it and throw it then why java provided so? plz...
5
by: Jeffrey Walton | last post by:
Hi All, What is wrong with the following? C# claims: "An unhandled exception of type 'System.OverflowException' occurred in mscorlib.dll Additional information: Value was either too large or too...
8
by: pjerald | last post by:
package test; import java.util.ArrayList; public class MyArrayList{ public static void main(String args) { ArrayList al = new ArrayList(); al.add("Jerald"); ...
3
anurag275125
by: anurag275125 | last post by:
Hello all.. I wanna know- is there concept of checked and unchecked exception in java or not? I didn't found any reference about this. please help me out.. thanks in advance...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.