3 Replies - 411 Views - Last Post: 18 November 2009 - 05:54 PM Rate Topic: -----

#1 silverkid  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 18-November 09

basic question about exceptions

Post icon  Posted 18 November 2009 - 12:56 PM

when an exception occurs that a method is unable to handle - does the program terminate and show the error number ? where does the error number and information about the error come from ? should the programmer while coding have an idea what kind of exception might occur. if so why does'nt he ensure that exception does not occur .
Is This A Good Question/Topic? 0
  • +

Replies To: basic question about exceptions

#2 Dogstopper  Icon User is offline

  • The Ninjaducky
  • member icon



Reputation: 2874
  • View blog
  • Posts: 11,047
  • Joined: 15-July 08

Re: basic question about exceptions

Posted 18 November 2009 - 12:58 PM

If the code is not surrounded by a try...catch block then (most of the time), it crashes. If there is a try { } catch { } block, then whatever is defined in the catch block is executed upon error.

Here's a good series of knowledge for Exceptions: http://java.sun.com/...ions/index.html
Was This Post Helpful? 1
  • +
  • -

#3 sakshamkum  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 19
  • View blog
  • Posts: 232
  • Joined: 09-June 09

Re: basic question about exceptions

Posted 18 November 2009 - 01:08 PM

in case the function called throw an Exception and that is not catched the compiler may give error.
in other cases they occour at the execution time being true for all cases
Was This Post Helpful? 0
  • +
  • -

#4 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8342
  • View blog
  • Posts: 31,880
  • Joined: 06-March 08

Re: basic question about exceptions

Posted 18 November 2009 - 05:54 PM

View Postsilverkid, on 18 Nov, 2009 - 11:56 AM, said:

when an exception occurs that a method is unable to handle - does the program terminate and show the error number ?

Yes this is why and how exception were written for...
we go up reversing the stack until you find a try/catch
if there is no try/catch up to the main() method the application crashes

View Postsilverkid, on 18 Nov, 2009 - 11:56 AM, said:

where does the error number and information about the error come from ?

95% of the time when Java throws an Exception it throws(new EXceptiontype(String param)) that is where the info comes from

View Postsilverkid, on 18 Nov, 2009 - 11:56 AM, said:

should the programmer while coding have an idea what kind of exception might occur.

hope so, or the mechanism would be useless. All API methods descibe which Exception they might throw

View Postsilverkid, on 18 Nov, 2009 - 11:56 AM, said:

if so why does'nt he ensure that exception does not occur .

You can always try/catch Exception or even catch Throwable to catch eveyrthing but this NOT a good coding practice
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1