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 .
basic question about exceptions
Page 1 of 13 Replies - 298 Views - Last Post: 18 November 2009 - 05:54 PM
Replies To: basic question about exceptions
#2
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
Here's a good series of knowledge for Exceptions: http://java.sun.com/...ions/index.html
#3
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
in other cases they occour at the execution time being true for all cases
#4
Re: basic question about exceptions
Posted 18 November 2009 - 05:54 PM
silverkid, 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
silverkid, 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
silverkid, 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
silverkid, 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
Page 1 of 1
|
|

New Topic/Question
Reply




MultiQuote






|