• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Basics of exception handling

 
mahesh deshpande
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For you all who are putting lot of hard work to get certified.
My question is very simple.
Why there is a special methods( like try, catch, finally etc.) to
detect any exception. How it is handled in other languages like
c or c++ or Fortran.( as I donot know any other computer language)
If Runtime exception are handled by java runtime environment then why not there is such provision to handle other kind of exception. I mean to say why the language has not been designed to take care of all exception so as to ease the programmer
 
Randall Twede
Ranch Hand
Posts: 4363
2
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am in the same boat as you. i dont know any other modern computer languages either. I have heard that VB provides for checked exceptions but I dont think C++ does.
 
Sam Wong
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
C++ definitely has exception handling mechanisms. Java got it from C++. However, C doesn't. You have to check return code for errors. Any RuntimeExceptions will either result in corrupted data or segmentation faults (core dump). Regarding Fortran, I don't remember it having exception handling either. Its been too long since I used it.
Now to answer why you need exception handling like try, catch. Its simple. It forces the developer to handle all possible exceptions. If it was just return codes, developers may forget to check them.
RuntimeExceptions and Errors are handled by the runtime environment because they can't be detected during compile time. All other exceptions are handled during compilation. So, in essence, all exceptions are handled one way or another.
 
Adrian Yan
Ranch Hand
Posts: 688
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Exception handling in other languages are more or less decided by the developers, because this, many programs have many bugs that simply missed by the developers.
The Java programming language solve this major problem by forcing developers to habdle exceptions, which eliminates many unnecessary bugs.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic