JAVA Exception

This is a discussion on "JAVA Exception" within the Other Programming Languages section. This forum, and the thread "JAVA Exception are both part of the Program Your Website category.


 Subscribe in a reader

Go Back   Webforumz.com > Main Forums > Program Your Website > Other Programming Languages

Notices




Reply
 
LinkBack Thread Tools
  #1  
Old Aug 30th, 2007, 03:36
Junior Member
Join Date: Sep 2005
Location: Beyond the seas there's a town,In hand of each child a branch of insight lies,I shall build a boat.
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
JAVA Exception

What is difference between throw and throws?

May you give me an example about that?May you explain about override exception?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote

  #2  
Old Aug 30th, 2007, 20:37
Up'n'Coming Member
Join Date: Jun 2007
Location: Birmingham, UK
Posts: 54
Thanks: 0
Thanked 0 Times in 0 Posts
Re: JAVA Exception

The throw keyword is used to actually throw an exception while the throws keyword just tells the compiler which exceptions may be thrown by a method.

Code: Select all
public Object pop() throws EmptyStackException
{
    Object obj;

    if (size == 0) {
        throw new EmptyStackException();
    }

    obj = objectAt(size - 1);
    setObjectAt(size - 1, null);
    size--;
    return obj;
}
See haw throws appears in the declaration of the method and throw appears in its body.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #3  
Old Aug 31st, 2007, 19:28
Junior Member
Join Date: Sep 2005
Location: Beyond the seas there's a town,In hand of each child a branch of insight lies,I shall build a boat.
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
Re: JAVA Exception

Hello!
Thanks!

But I mean an example for throw,and another for throws,Thanks in advance!

May someone give me a list of difference between checked and unchecked exceptions?why they called "checked" or "unchecked"
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #4  
Old Sep 9th, 2007, 20:19
Junior Member
Join Date: Sep 2005
Location: Beyond the seas there's a town,In hand of each child a branch of insight lies,I shall build a boat.
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
Re: JAVA Exception

Hi!

http://java.ztor.com/fundamental/main/

Handling Exceptions
You can handle exception otherwise you must declare it. Also you can handle some exceptions and declare others.


Handle Exceptions
Code: Select all
public void myMethod() {
try {
  . . .
}
catch (ExceptionType1 e) {
  . . .
}
catch (ExceptionType2 e) {
  . . .
}
finally {
  . . .
}


Declare Exceptions
Code: Select all
public void myMethod() throws ExceptionType1,ExceptionType2 {
  . . .
}
May someone explain more about difference between these?When do we use declare exception?When to use handle exception?



Quote:
You declare that a method throws an exception if the problem can't be handled in the method. You handle the exception in the method if you can handle the error and continue with the method.

May show this by an example?



Thanks in advance

Last edited by karinne; Sep 10th, 2007 at 13:15. Reason: Please use [ code ]...[ /code ] tags when displaying code.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Reply

Tags
exception

Thread Tools

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to make an exception to an “if ….” vandiermen PHP Forum 2 Sep 10th, 2007 12:59
tried java now c++ alexgeek Other Programming Languages 49 Sep 7th, 2007 06:15
Java/GUI/Server Developer (Java, EJB/Hibernate, SWING) - Berkshire Web JobBot Job Opportunities 0 Jan 16th, 2007 09:30
PHP vs Java Lue PHP Forum 0 Sep 13th, 2006 19:00
Java JDK 1.4.2 gecastill Other Programming Languages 5 Aug 4th, 2005 12:38


All times are GMT. The time now is 22:48.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42