I think checked exception are indeed annoying, specifying what exception types can be thrown in the method documentation it's pretty much enough. However I don't think ugliness is the main reason why exception should be avoided as much as possible, I think is performance: You get a performance penalty when you throw exceptions.
About the return values, since .NET 2.0 the TryParse calls were introduced and it works pretty well in the case you don't need to know the details of a failed parsing operation which I think is the 95% of the cases:
public static bool TryParse(
string s,
out int result
)
I'm not saying we should stop using exceptions, but we should have more High poerfomance alternatives like this in Java.
This is a common dogma in .net land. If we're being fair a more accurate statement would be "you currently get a performance penalty when you throw exceptions in Microsoft's implementation of .net".
Exceptions are much faster in mono than Microsoft's .net[0], are much faster still in Java[0] and can be made as fast as goto in Java in some circumstances[1], particularly if you control the Exception class being thrown.
Claiming Exceptions are slow is like saying "Java is slow". Languages and language features aren't slow, implementations are.
These are very interesting articles benjiweber and you are right, it depends of the implementation. My point is that there are some cases in which you can gain some speed by no throwing exceptions at all and TryParse is a perfect example of this(at least in .NET).
Also exception-handling blocks might prevent the Virtual Machine from inlining the method(again, at least in .NET), is this true for the JVM too?
About the return values, since .NET 2.0 the TryParse calls were introduced and it works pretty well in the case you don't need to know the details of a failed parsing operation which I think is the 95% of the cases:
public static bool TryParse( string s, out int result )
I'm not saying we should stop using exceptions, but we should have more High poerfomance alternatives like this in Java.
More info here: http://msdn.microsoft.com/en-us/library/f02979c7.aspx