
Originally Posted by
chrisvil
@
stealthghost: Thanks for the reply. This is not an assignment but a narrative research regarding the comparative studies on handling exception in most popular programming language. Choosing the above programming languages above is through the TIOBE programming language popularity community index.
I am not taking answers from student who do not have a solid experience in programming, what I need is the input from an experience programmer who does actual coding specifically in handling exceptions mechanism.
Programmers around the world experience problems with error trapping in how, when and where to apply the available exception handling in every programming language.
As a software engineer I have some but need to know other experiences for my research regarding this matter.
This should be in your original question, for us to know the context on why do you ask.
Also, you should share what you know at hand so that answers will not be duplicated.
Probably im not experienced as what you have described but maybe we can add or maybe debate about general practice.
--------------
As far as i know, Java or .net are richest built-in exception handling because of the checked|unchecked exception handling.
C++ doesnt have checked (maybe with the new C++ spec); it has unchecked exception handling
C doesnt have exception handling built-in aside from if-else (maybe with the new spec).
Objective-C have exception unchecked handling; not sure with unchecked (anyone?)
As you can see, most of them have built-in exception handling, so the language dont have issue.
I think the better queston is what are the general practice.
My general practice are:
We should write method with unchecked exceptions aka runtime exception that are thrown when you have system outage like Database down, NullPointerException, Network is down or File system is down should be re-thrown. These are the exceptions that the users cannot do anything about it, meant to be ignored and just log.
To handle unchecked exception is, ideally, you shouldnt handle it, just let the system rethrow it until it reaches to the end of the stack of app server who is invoking it (e.g. jboss/tomcat/jetty or application server), and the app server itself should have feedback to the client (system or user) about the system failure (error=500), or maybe alert to the admins/operators so that it will have have manual intervention.
We should write method with checked exception if it's an exception related to the business logic such as ZeroDivisorException, LowBalanceException, LowFuelExcepton, InvalidPasswordException. It means they are exceptions that user can do anything about why it's happening and avoid inputting those invalid values.
To handle the checked exception, the client program that uses methods with checked exception are required to handle it. For example:
Code:
public String authenticate(String user, String password) throws InvalidPassWordExcepton {
// blah
return token;
}
public void doSomething(String
try {
String token = authenticate(user, password);
} catch (InvalidPassWordExcepton e) {
// you are hanlding invalid login
tryAgain();
}
}