Re: What Are Your C# Pain Points, Really?
Posted: Mar 22, 2007 5:56 PM
> > You know if you check the documentation.
> Sure, but that can only be done if it the exceptions are
> indeed documented, which is not always the case with some
> of third party libraries I have encountered.
Poor work on documentation, design, or implementation of a library can't be solved by checked exceptions. Even if it's a Java library, the implementation might just be silently swallowing the exceptions anyway.
> The exceptions you have to handle are exactly the ones the
> writer of a method choose to expose. If he exposes more
> than "top-level-exceptions", I would say that the library
> has a design flaw. If that is the case it would be obvious
> when you look at the method signature in Java, but more of
> a guessing game in C#.
One would hope that the exceptions that are exposed are the ones that aren't appropriate to be handled in the method itself.
The point is that if method D which can throw exception 1 is called by method C which can also throw exception 2 is called by method B which can throw exception 3 is finally called by method A and it isn't appropriate for any of these exceptions to be handled by B, C or D methods, method A has to handle them or declare them throwable. Now if method D is modified to throw another exception, methods A,B and C will no longer compile. In a large system this could be a maintenance nightmare.
> Still, as I said in my original post, you cannot mark
> variables on the stack as readonly, which is possible with
> final in Java. This is something I really miss in C#.
Perhaps I don't fully understand what you're trying to accomplish. It's true that C# doesn't allow you to declare a local variable as readonly, but you can declare it as const. What can you do with final in this case, that you can't do with const? Perhaps a simple example would make it clear.