Article Discussion
The Trouble with Checked Exceptions
Summary: Anders Hejlsberg, the lead C# architect, talks with Bruce Eckel and Bill Venners about versionability and scalability issues with checked exceptions.
45 posts.
The ability to add new comments in this discussion is temporarily disabled.
Most recent reply: May 6, 2013 11:03 AM by Gregg
    Bill
     
    Posts: 409 / Nickname: bv / Registered: January 17, 2002 4:28 PM
    The Trouble with Checked Exceptions
    August 17, 2003 5:17 PM      
    Anders Hejlsberg says, "The concern I have about checked exceptions is the handcuffs they put on programmers. You see programmers picking up new APIs that have all these throws clauses, and then you see how convoluted their code gets, and you realize the checked exceptions aren't helping them any."

    Read this Artima.com interview with C# creator Anders Hejlsberg:

    http://www.artima.com/intv/handcuffs.html

    What do you think of Ander's comments?
    • Rich
       
      Posts: 1 / Nickname: richd / Registered: August 18, 2003 2:44 PM
      Re: The Trouble with Checked Exceptions
      August 18, 2003 6:47 PM      
      You may be interested in the discussion on this article at LtU: http://lambda.weblogs.com/
    • Joost de
       
      Posts: 15 / Nickname: yoozd / Registered: May 15, 2003 4:13 AM
      Re: The Trouble with Checked Exceptions
      August 18, 2003 11:27 PM      
      I think condemning checked exceptions as a whole is a mistake. Anders Hejlsberg very clearly explains the results you get when you make everything a checked exception. But I think it's more subtle then "checked exceptions are evil". There is a real use for checked exceptions. I quote Rod Johnsons book:

      Question: Should all callers handle this problem? Is the exception essentially a second return value for the method?

      Example: Spending limit exceeded in a processInvoice() method.

      If 'yes': Use a checked exception and take advantage of Java's compile-time support.

      Question: Will only a minority of callers want to handle this problem?

      Example: JDO exceptions

      If 'yes': Extend java.lang.RuntimeException. This leaves callers the choice of catching the exception but doesn't force them to.

      Question: Did something go horribly wrong? Is the problem unrecoverable?

      Example: A business method fails because it can't connect to the application database.

      If 'yes': Extend java.lang.RuntimeException. I do think a java.lang.Error would be more suitable here. According to javadoc an Error signals a "abnormal condition that a reasonable application should not try to catch".

      end of quote

      groeten uit nederland
      Joost
    • Stephen
       
      Posts: 1 / Nickname: stepjam / Registered: August 18, 2003 10:59 PM
      Re: The Trouble with Checked Exceptions
      August 19, 2003 3:16 AM      
      I can see two problems in not having checked exceptions.

      1. How do you know that the method throws an exception that you are meant to handle. Especially when you write code that uses some toolkit than in turn uses someother toolkit.

      I know that exceptions can be documented in C# but can you find the possible exceptions that may be thrown all the way down the call tree?.

      2. It must seem to ecourage sloppy coding, in that to reduce try/catch noise one doesn't bother to include any and let the caller worry about it. Almost like the VB hell of "ON ERROR RESUME". Of course one can have sloppy code with checked exceptions and the loud noise that might come from try/catch proliferation.

      As for versioning I'd have thought that if you change the signature/contract of a method then the caller has to defend against it instead of quietly ignoring the fact that the method may now fail because a new reason.

      We only have to look at the amount of software outthere that complains using dialogs "Can't do xxx" then "Unable to ..".
    • Brandon
       
      Posts: 3 / Nickname: bcorfman / Registered: August 5, 2003 0:07 AM
      Re: The Trouble with Checked Exceptions
      August 19, 2003 8:03 AM      
      Anders Hejlsberg wrote:
      C# is basically silent on the checked exceptions issue. Once a better solution is known—and trust me we continue to think about it—we can go back and actually put something in place.

      This proves to me that this guy is smart and cares about what he's doing. C++ exceptions were an experiment, and Java checked exceptions were an experiment too. Why do we want experimental features in a programming language? Let's have well-defined, thought-out features in our languages; they are not some designers' playground.

      I think that proper (and improper) handling of exceptions will continue to be an issue until we get transactional semantics in our programming languages. How else do you guarantee that you recover properly when an exception is thrown? The problem is too hard to handle correctly otherwise.
    • Sakesun
       
      Posts: 8 / Nickname: sakesun / Registered: August 18, 2003 10:00 PM
      Re: The Trouble with Checked Exceptions
      August 19, 2003 2:40 AM      
      How about having "unexpects" keyword ?

      void methodNumberOne() throws ACheckedException {
      ...
      }

      void methodNumberTwo() unexpects ACheckedException {
      ...
      methodNumberOne();
      ...
      }

      The compiler then compile methodNumberTwo() as like:

      void methodNumberTwo() {
      try {
      ...
      methodNumberOne();
      ...
      }
      catch(ACheckedException e) {
      throw new UnexpectedException(e);
      }
      }


      Of course, UnexpectedException is a RuntimeException descendent. Is this a good idea ? This way you can explicitly declare what exceptions are unexpected and the code is totally unprepared for those situations.
      • Matt
         
        Posts: 62 / Nickname: matt / Registered: February 6, 2002 7:27 AM
        Re: The Trouble with Checked Exceptions
        August 19, 2003 11:11 AM      
        > How about having "unexpects" keyword ?

        It is already there, but it's called "//unexpects". ;-)
        • Sakesun
           
          Posts: 8 / Nickname: sakesun / Registered: August 18, 2003 10:00 PM
          Re: The Trouble with Checked Exceptions
          August 19, 2003 7:16 PM      
          > It is already there, but it's called "//unexpects".
          > ;-)

          Having "unexpects" as a keyword make it less labourous to chain many exception, and make it more explicit also.
          • Matt
             
            Posts: 62 / Nickname: matt / Registered: February 6, 2002 7:27 AM
            Re: The Trouble with Checked Exceptions
            August 20, 2003 0:43 AM      
            Smart-ass quips aside, I think I agree with Brandon on this. Java doesn't need more exception cruft, it needs less. My guess is that Sun wanted Java to have mass appeal, which means it needed to try to be idiot-proof (at least a lot more so than C and C++). Hence, checked exceptions, with the thinking that API developers could force proper exception handling down the collective throats of the masses. Naturally, when it comes to defeating foolproof schemes, the fools reveal their genius -- and the world is filled with empty catch clauses.

            When I was first exposed to checked exceptions -- "in the small," of course -- they seemed pretty darned nifty. The compiler would tell me exactly which exceptions I should be expecting from a particular call and I would dutifully handle them -- and, I even didn't have to do the footwork of looking them up in the documentation! However, after the novelty wears of (which is pretty quickly), it just amounts to a lot of extra busywork and distraction. I think it has a great anal-retentive appeal, but I question whether it makes for better code. In fact, it may lead to a false sense of "completeness" since it is entirely possible the API writer may have decided to throw RuntimeExceptions exclusively.

            What I think would be ideal is all unchecked exceptions, as in C#, combined with a smart IDE that will do auto-completion of catch clauses, filling in all possible exceptions that could occur in the preceding try block (yes, it would need to look into calls of calls of calls and so on). This might not be feasible in a dynamic language like Python, but should be in Java or C#.
    • Jan
       
      Posts: 1 / Nickname: jploski / Registered: August 20, 2003 4:32 AM
      Re: The Trouble with Checked Exceptions
      August 20, 2003 3:14 PM      
      The line of Heilsberg's argumentation seems to be the following: "many programmers misuse checked exceptions, so let's remove the language support for them altogether". What kind of logic is this? This simply means acknowleding the sorts of described "worst practices" and letting them spread further.

      Complaining about method signatures becoming fatter because of too many checked exceptions? Think about why you are passing all those weird exception types on to your clients! Making your clients deal with exceptions that stem from implementation details of your module is a design error.
    • alexei
       
      Posts: 1 / Nickname: javakid / Registered: August 25, 2003 5:49 PM
      Re: The Trouble with Checked Exceptions
      August 25, 2003 9:53 PM      
      ... Anders Hejlsberg point of view shows once again that microsoft just wants to make junior programmer being able to write bad code!

      I wonder if he read the chapter about how to use the java exceptions handling mechanisms in Joshua Bloch's Effective Java Programming Language Guide.
    • Frank
       
      Posts: 135 / Nickname: fsommers / Registered: January 19, 2002 7:24 AM
      Re: The Trouble with Checked Exceptions
      August 20, 2003 11:53 PM      
      Whether checked exceptions are useful or not depends on a more fundamental question: Useful for what?

      If one's goal is to make a programming language popular for programmers (so that programmers start using it, and start to like it), then I agree that things should be kept simple - just don't cause many troubles for the programmer, just keep things simple and smooth. Then checked exceptions are more trouble than they're worth.

      On the other hand, if one's goal is to build systems that can survive all kinds disasters and exceptional conditions without a blink, then checked exceptions are very useful, indeed. They're useful, because they give you a programmatic interface to failure. And that interface makes it possibly easier to recover from those failures.

      Traditionally, the latter category of software contained things like operating systems, file systems, real-time systems, etc. For instance, it's hardly acceptable to just pop up a dialog box, "Sorry, disk sector XXX failed. Please reboot." Rather, you just want to hide that error from the user, and route around it. Indeed, disk controllers just handle such things themselves, mapping around bad disk sectors, without even letting an OS know about the problem. Traditionally, end-user applications are much less industrious: You can always pop up that message dialog and push exception handling up the chain to the user.

      But the standards are changing, and end-user software will have to become as reliable and OSs, file systems, disks, or embedded systems. For instance, today it's still OK to pop up a dialog to the effect: "Can't save file. File system full." That may no longer be acceptable in a few years: People don't care about file systems, they just want the system to save their darn file (even if it means that the system now has to borrow another machine's file system perhaps).

      As an increasing number of people use software, users' tolerance is going to diminish: They will demand software that can fix its own problems. In turn, they will demand that programmers actually consider the exceptional conditions AND write the software so it recovers from those exceptions.

      This is already happening in the industry I am in. Displaying an error message "Cannot connect to database" might be acceptable in an environment that caters to programmers or system administrators. But displaying that message to end-users who don't know what a database is, or why you would have to "connect" to one, is going to be a serious problem. Such users lose patience very quickly, and dial the tech support line with great indignation: "Your system doesn't work. I'm losing money, I can't conduct business. Come out here right away, and fix this." They can't and won't follow instructions - they will want you to go out to their location and fix their problems, even if it means only a database reboot.

      From a business point of view, that's going to be an extraordinarily unprofitable venture. So, instead, you probably want the program to declare that connection exception, and then think of all the ways your program can reconnect to that database, and create an exception handler that's activated by that connection exception. Or, if all fails, ship a log file back to your support office even BEFORE the customer notices the error (or at least before they call).

      I like to declare only those exceptions where there is a reasonable chance of automated recovery. But once I declare those exceptions, that says, in essence, that the corresponding recovery routines are now a system requirement - the system doesn't meet its requirements without them.

      I do agree that declaring exceptions from which automated recovery is hardly possible, is an undue burden, and such a practice completely obliterates the value of checked exceptions: It simply invites programmers to leave empty catch clauses in their code.

      In summary, as the standard for software quality rises, checked exceptions will continue to play an important role in making software more robust and reliable. They can be an inmune system to software. And an abused immune system is just as bad as an organism without one altogether.
      • Greg
         
        Posts: 3 / Nickname: glucas1 / Registered: August 18, 2003 2:47 AM
        Re: The Trouble with Checked Exceptions
        August 21, 2003 11:32 AM      
        > I like to declare only those exceptions where there is a
        > reasonable chance of automated recovery. But once I
        > declare those exceptions, that says, in essence, that the
        > corresponding recovery routines are now a system
        > requirement - the system doesn't meet its requirements
        > without them.

        Well said. The java language gives us a useful tool to describe error-handling requirements as part an interface. Like most tools, just because it's there doesn't mean you should use it every time. Deciding what to declare as checked exceptions is an important part of desigining an API.

        The language feature should not be tossed out just because API designers are misusing it. As someone said earlier, if your interface includes all kinds of checked exceptions then it probably exposes too much of the internal implementation. And *that* is what leads to the versioning and scalability problems raised by Hejlsberg.

        Some people have said that checked exceptions are an attempt to make java idiot-proof, a sort of dumbing-down approach to protect programmers from themselves. To me, that focuses on the wrong side of the equation. The goal of checked exceptions is not to make *using* an interface easier, it is to enable programmers to *design* more expressive interfaces.
        • Matt
           
          Posts: 62 / Nickname: matt / Registered: February 6, 2002 7:27 AM
          Re: The Trouble with Checked Exceptions
          August 21, 2003 3:38 PM      
          > Some people have said that checked exceptions are an
          > attempt to make java idiot-proof, a sort of dumbing-down
          > approach to protect programmers from themselves. To me,
          > that focuses on the wrong side of the equation. The goal
          > of checked exceptions is not to make *using* an interface
          > easier, it is to enable programmers to *design* more
          > expressive interfaces.

          The whole purpose of designing anything is so that it can be used, isn't it? What's the good of a complicated and hard-to-use API that affords the designers all the expressiveness they could possibly imagine? Programmers usually over-design things in the wrong places anyway, so why give them more ammunition?

          More importantly, it doesn't necessarily follow that a more heavily embellished interface is a more expressive interface. I think Anders was saying that he saw no clear imperative for the type of implementation of checked exceptions seen in Java. That's not saying they are a bad thing, just that he didn't see them as a valuable enough feature to warrant inclusion in C#.

          It is kind of interesting in this light that C# is much more restrictive with inheritance, requiring lots of pre-planning in the use of virtual, then subsequently, in derived classes new or override. It seems like this treatment is philosophically at odds with the checked exceptions treatment. Hopefully Bill and Bruce asked Anders about this apparent dichotomy in one of the later segments of the interview...
          • Greg
             
            Posts: 3 / Nickname: glucas1 / Registered: August 18, 2003 2:47 AM
            Re: The Trouble with Checked Exceptions
            August 22, 2003 11:15 AM      
            > The whole purpose of designing anything is so that it can
            > be used, isn't it? What's the good of a complicated and
            > hard-to-use API that affords the designers all the
            > expressiveness they could possibly imagine?

            I think you're right -- a complicated interface is not necessarily easy to use. To argue checked exceptions are there to 'make things easy for programmers' just isn't true, because they don't really make things easy.

            What the do allow for is an interface that conveys more information to the caller. As with any kind of information, sometimes more is useful and sometimes more is just distracting. And like everything else in software, it's up to the developer to walk that line.

            On the other hand I don't think it follows that a less complex API is necessarily easy to use. public Object doSomething(Object[] theObjects) is certainly not complicated. But I suspect it's very difficult to use in any meaningful way.

            Anyway, I seem to have gotten away from my original point. I agree that checked exceptions might not be worth propagating to new languages, or that a better mechanism to accomplish the same thing might be designed. I just haven't yet heard a convincing argument.

            If we're worried that a method throws too many checked exceptions and therefore puts too much burden on the caller, than the method is poorly designed -- and it has nothing whatsoever to do with Java as a language. You could make the exact argument Anders is making about method parameters, or return codes, or anything else. 'This method I have to call takes 15 parameters, and with every release they add a new one that breaks all my code.' One would point out that the method probably shouldn't take 15 parameters. One would not say "a language should not allow you to specify more than one parameter to a method."

            It's also worth mentioning that lots of languages are very powerful and useful precisely because they have different goals than Java with respect to precise interface design, maintainable and self-documenting code, etc. If I'm writing perl, I don't want to deal with checked exceptions. This isn't because they are useless, it's because I'm seeking a different end result. But for a language that is oriented towards interface design, allowing interfaces to specify out-of-band information in the form of exceptions is very useful.
            • Laird
               
              Posts: 1 / Nickname: fatdog / Registered: April 12, 2003 0:01 PM
              Re: The Trouble with Checked Exceptions
              August 25, 2003 10:01 PM      
              I have the suspicion that that Anders is talking mostly about exception handling in simple user interfaces where a global approach might not be so bad as long as an underlying C++ library is handling the real problems in the program. If you see C# as a replacement to visual basic I can understand this mindset. However as was mentioned earlier, when you think about using Java or C# for more system level problems, I think the context afforded by handling a checked exception is crucial.

              I also think that the exponential growth of declared exceptions is really a bogus argument. I think people felt this way back in Java1.0 days, when design of an exception hierarchy might not have been considered an integral part of program logic. But now I think people quite commonly make use of polymorphic exceptions and exception chaining. In fact I am quite puzzled that none of the interview nor the followup discussion discussed either of these two features of java exception handling. If an underlying library throws too many exceptions, chain them in a cleaner excpetion that your code knows about. If you throw too many low level exceptions that dont share common ancestry in your own code, thats your fault.
    • Sanjay
       
      Posts: 1 / Nickname: sdwarka / Registered: August 13, 2003 11:11 PM
      Re: The Trouble with Checked Exceptions
      August 28, 2003 4:23 AM      
      Anders Hejlsberg says: The scalability issue is somewhat related to the versionability issue. In the small, checked exceptions are very enticing. With a little example, you can show that you've actually checked that you caught the FileNotFoundException, and isn't that great? Well, that's fine when you're just calling one API. The trouble begins when you start building big systems where you're talking to four or five different subsystems. Each subsystem throws four to ten exceptions. Now, each time you walk up the ladder of aggregation, you have this exponential hierarchy below you of exceptions you have to deal with. You end up having to declare 40 exceptions that you might throw. And once you aggregate that with another subsystem you've got 80 exceptions in your throws clause. It just balloons out of control.

      We'd encountered situations like this in an RMI project.

      We faced some of the issues Anders mentions with using checked exceptions and so we made a conscious decision to define a hierarchy of unchecked exceptions for the application. This is not to say we discarded checked exceptions altogether, we just used them as we saw fit.

      We also needed to handle checked exceptions from the server side that were not application related. So we designed a wrapper for the parts that talked to the server that translated the non-application exceptions to application (mostly) unchecked exceptions. Yes, we did lose some information in the process but we moved ahead.

      This way, we were able to achieve a reasonable balance.

      Overall, you do run into some problems with checked exceptions and some other without, but wouldn't checked vs. unchecked be a matter of design decisions?
    • Cameron
       
      Posts: 2 / Nickname: grom / Registered: July 21, 2003 6:10 PM
      Re: The Trouble with Checked Exceptions
      August 29, 2003 0:19 AM      
      Take the following code as an example:
      Connection conn = null;
      PreparedStatement stat = null;
      ResultSet rs = null;
      try {
        conn = DbHelper.getConnection();
        stat = conn.prepareStatement("SELECT * FROM addressbook");
        rs = stat.executeQuery();
        while(rs.next()){
          // print out name & email
          System.out.println("Name: " + rs.getString("name"));
          System.out.println("Email: " + rs.getString("email"));
        }
      } finally {
        if (rs != null) rs.close();
        if (stat != null) stat.close();
        if (conn != null) conn.close();
      }
      


      All the database calls can result in a SQLException which are checked exceptions. At production time, this code should only fail if the database connection is lost or the database crashes. As a result of SQLException being a checked exception the above method will either have to declare to throw SQLException or wrap SQLException (which is most likely the better design choice).

      So the problem with checked exceptions is that it forces the library user to handle the exception even if this isn't required. In the above code, we should not be catching exceptions from the query execution and result set retrieval since exceptions from these calls will most likely be from a coding error. Note however, part of this problem is due to lack of exception hierarchy for SQL exceptions.

      Anyway, I still think checked exceptions are useful but they must be used with care. This is the problem with checked exceptions. They cause problems for the API user if they have been used where they should not have.

      I think a good start for determining wether to use unchecked or checked would be Rod Johnson's rules in Chapter 4 of "Expert One-on-One: J2EE Design and Development" which you can get from http://www.wrox.com/books/sample-chapters/samplechapter_0764543857.pdf
      • Frank
         
        Posts: 135 / Nickname: fsommers / Registered: January 19, 2002 7:24 AM
        Re: The Trouble with Checked Exceptions
        August 29, 2003 11:15 PM      
        > All the database calls can result in a SQLException which
        > are checked exceptions. At production time, this code
        > should only fail if the database connection is lost or the
        > database crashes.

        Not really. The code can also fail if someone, unbeknown to your application, changes the database schema so that the specified relations and fields no longer exist. Of course, the question is, does it help us to know what went wrong when accessing the database? In the case of this simple query, it might not matter whether the DBMS was down, or a table changed. So, in this simple example, it might not matter whether SQLException is a checked exception.

        > So the problem with checked exceptions is that it forces
        > the library user to handle the exception even if this
        > isn't required.

        But it is required. The app should handle this exception. For instance, it might fail over to a backup database, etc. If a developer has to expect this exception (because it's declared by the JDBC API), that gives the programmer another chance to think and consider what remedies can be applied when the exception does happen.

        > In the above code, we should not be
        > catching exceptions from the query execution and result
        > set retrieval since exceptions from these calls will most
        > likely be from a coding error.

        Or, again, a change in the system (ie. schema change). But in the case of an update, there can be a whole set of other reasons for SQLException to occur (ie. attempts to violate primary key constraints, incorrect data types, etc). Which brings us to....

        >Note however, part of this
        > problem is due to lack of exception hierarchy for SQL
        > exceptions.

        Which is why I think typed exceptions should be added to SQL. Currently, each DBMS generates its own error codes when SQL errors occur. For instance, if I try to do an insert with values that would violate primary key constraints, the DBMS might generate some error code. That code, in turn, bubbles up as an SQL Exception. What I'd really like to see is for the SQL language to have a typed exception hierarchy. For instance, it might throw a "IntegrityViolationException, " etc. Having these typed exceptions generated as part of SQL statements would really help database application development.

        For instance, suppose you wanted to insert a customer record into a database table with a primary key of a customer's social security number. Currently, I'd have to write code such as:
        try {
        PreparedStatement st =
        dbconnection.prepareStatement("select ssn from customer where ssn=?");
        st.setString(1, customer.getSSN());
        ResultSet rs = st.executeQuery();
        if (rs.next()) {
        //customer is already in DB,
        //inserting would cause an SQLException
        //just close db objects and return
        } else {
        //do the insert
        st = dbConnection.prepareStatement("insert into customer ....")';
        dbConnection.commit();
        }
        } catch (SQLException e) {
        ////
        }

        This is really bad code. I need to check first if the customer is already in the database - if I try to the insert and the customer is already in the database, I get an SQLException. But I can't tell whether the SQLException occurred because the DBMS went down, or because if the attempted integrity violation. So not having typed SQL exceptions renders SQLException itself more or less useless. What I'd like to see, instead, is something like:

        try {
        PreparedStatement st =
        dbConnection.prepareStatement("insert into customer .....");
        st.executeUpdate();
        dbConnection.commit();
        } catch (SQLIntegrityException e) {
        ///this is OK - the customer is already there, so do nothing
        } catch (SQLConnectionException e) {
        //this is not OK - fail over, or do some other recovery work here
        }

        But those different DBMS exceptions must originate from the database, as a result of the SQL statements. That can only happen if there is a standard hierachy of SQL exceptions defined by SQL itself.
        • Cameron
           
          Posts: 2 / Nickname: grom / Registered: July 21, 2003 6:10 PM
          Re: The Trouble with Checked Exceptions
          August 30, 2003 2:21 AM      
          >> All the database calls can result in a SQLException which
          >> are checked exceptions. At production time, this code
          >> should only fail if the database connection is lost or
          >> the database crashes.
          >
          > Not really. The code can also fail if someone, unbeknown
          > to your application, changes the database schema so that
          > the specified relations and fields no longer exist. Of
          > course, the question is, does it help us to know what went
          > wrong when accessing the database? In the case of this
          > simple query, it might not matter whether the DBMS was
          > down, or a table changed. So, in this simple example, it
          > might not matter whether SQLException is a checked
          > exception.

          But it does matter and that's my point. Since it is checked you either wrap it or pass it on by declaring to through SQLException. In a layer design, you would wrap the exception. In the example that I gave, although there could be a database schema change having to handle this is not reasonable. How often is this going to happen? The JDBC API designers think it is often. I don't. For example, in a standalone application where it is the only process accessing the database, there is a coding error if rs.getString("name") fails. This is the problem with checked exceptions, it makes assumptions about how you will use the API. In the case of my example, wrapping the exception adds no value but I don't want to throw an SQLException on the interface.

          >> So the problem with checked exceptions is that it forces
          >> the library user to handle the exception even if this
          >> isn't required.
          >
          > But it is required. The app should handle this exception.
          > For instance, it might fail over to a backup database,
          > etc. If a developer has to expect this exception (because
          > it's declared by the JDBC API), that gives the programmer
          > another chance to think and consider what remedies can be
          > applied when the exception does happen.

          But I don't want to handle the exception. I want to tell the user that the database needs to be restarted and contact the system admin with a generic exception handler. Or maybe the database is an in-process database (eg. HSQLDB) and therefore this exception means that we should exit the system. A checked exception also doesn't ensure that I consider a lost connection, since it is possible just to shallow it. Checked exceptions don't stop lazy programming. And they can be annoying for those that take the time to think about their code.

          Although checked exceptions do have a purpose. I just think SQLException is a prime example where it should not have been used. The Spring framework translate SQLException to unchecked exception. Plus it has an exception hierarchy so no dealing with vendor error codes.
          • Frank
             
            Posts: 11 / Nickname: fmitchell / Registered: January 31, 2003 9:53 AM
            Re: The Trouble with Checked Exceptions
            August 30, 2003 4:02 PM      
            Just my 0.02 Euros on this:

            One of the prime problems with Java exception handling, in theory and in practice, is that there's no distinction between "coding errors" -- violated assumptions, internal resource exhaustion, etc. -- and uncommon but serious external conditions -- I/O errors, O/S signals, server-side errors, etc. Compounding this problem, many Java APIs wrap a whole class of implementations with some common -- and sometimes overly abstract -- layer.

            Therefore, many APIs, like java.db and javax.jms, throw general exceptions on every single method call, just in case some implementation might have some internal or external error at that point. APIs indicate all errors, even easily avoidable ones, by throwing an exception. For example, an implementation may only allow a finite number of sessions or connections (SQL, JMS, whatever); only the message, and occasionally the exception class, could inform the user what happened ... unless it's been swallowed somewhere in an ill-written or empty catch clause by an annoyed developer.

            Ideally Java would have a distinction between common and therefore checked external problems like IOException, and unchecked but documented Eiffel-style "contract" assertions of internal assumptions. It would also be nice if APIs considered a range of possible implementations and added queries to detect contract violations before they happened, and place exceptions only where unpreventable exceptions could happen: committing a transaction, sending a message, making an RMI or RPC call.
            • Andrew
               
              Posts: 2 / Nickname: methusaleh / Registered: February 14, 2003 10:40 PM
              Re: The Trouble with Checked Exceptions
              September 7, 2003 10:24 PM      
              What about a software language that can declare where an exception must be trapped?

              Eg: throws IOException caughtby Caller, Classname, Main

              Where Caller means the exception must be caught by the code invoking the method. Classname means that the exception will be unchecked until it reaches/passes through a specified class. Main could indicate that the application must at some point trap it. etc

              I guess this could be extended to allow the thrower to specify at runtime who can actually catch the exception.

              Also, as stated in the prior post this could also be added via 'design by contract' allowing both the caller and method to force exception checking.

              (Hope I have understood the whole issue properly)
    • John
       
      Posts: 1 / Nickname: jtcaway / Registered: May 9, 2003 6:30 AM
      Re: The Trouble with Checked Exceptions
      August 19, 2003 5:55 AM      
      > Adding a new exception to a throws clause in a new
      > version breaks client code. It's like adding a
      > method to an interface.

      Exactly! This is what you want to happen. If you think it's important enough to be part of the contract (in the throws clause of your API), then you want client code to break. If not, throw a RuntimeException.
      • Kirthi
         
        Posts: 1 / Nickname: kirthi / Registered: September 24, 2003 0:34 AM
        Re: The Trouble with Checked Exceptions
        September 24, 2003 4:41 AM      
        I agree. Also this is something that has been raised a little too late.
    • Greg
       
      Posts: 3 / Nickname: glucas1 / Registered: August 18, 2003 2:47 AM
      Re: The Trouble with Checked Exceptions
      August 18, 2003 7:21 AM      
      I haven't decided exactly where I fall in the checked/unchecked exception debate, but I can't fully agree with the versioning issue presented here.

      Anders says that if an interface is changed to add a new exception then all existing clients are broken. The argument is that most clients aren't actually handling the exceptions anyway, they're letting them get handled farther up the stack.

      In general a component or subsystem that can throw many different exceptions should provide a base exception class. Methods that wish to defer handling of exceptions can then add "throws SomeBaseException" and accomplish two things: deal with any current and future subtypes of SomeBaseException; and make it explicit that this method does not try to handle that set of exceptions. Methods that *do* need to deal with one or more of the possible exceptions can catch the ones needed (and still declare "throws SomeBaseException", if that's the desired behaviour).

      On the other hand, we've all seen lots of code with "throws exception" and those empty catch clauses. This does suggest a problem with the feature. Rather than discarding it altogther, perhaps there's some way to encourage users to use it properly?
      • Matt
         
        Posts: 62 / Nickname: matt / Registered: February 6, 2002 7:27 AM
        Re: The Trouble with Checked Exceptions
        August 18, 2003 8:38 AM      
        > Rather than
        > discarding it altogther, perhaps there's some way to
        > encourage users to use it properly?

        What is the "proper usage" then? I think that Anders might have been saying that a big problem with the Java implementation is that there is no good proper usage.
      • Ram
         
        Posts: 2 / Nickname: rama236 / Registered: August 18, 2003 3:08 PM
        Re: The Trouble with Checked Exceptions
        August 18, 2003 7:18 PM      
        I agree. Also it is a bit hard to realize the Exception numbers like 40 - 80 Exceptions in an application. Can anybody please let me know if this is the case in huge systems? Then the exception design should consider having a common base class for the system.
      • Michael
         
        Posts: 1 / Nickname: fuseboy / Registered: August 18, 2003 4:28 AM
        Re: The Trouble with Checked Exceptions
        August 18, 2003 8:47 AM      
        I agree - I think the scalability and versionability problems he presents here are symptoms of an API design that exposes clients to too much internal detail.

        Methods that throw multiple checked exceptions are assuming that the client will want to treat these differently (and that this desire is important enough to justify numerous catch blocks).

        In some cases, there may be a realistic expectation that the client but in many cases not - as Anders implies with his comment that the finally block is the important part of exception handling.

        A common root exception in the hierarchy (e.g. MyApiException) isn't always possible, either, as the root cause exception might be from another API, such as FileNotFoundException (and creating MyApiFileNotFoundException extends MyApiException is crazy).

        A way of dynamically composing a hierarchy would help, that way I can throw a single exception, MyApiException, and clients can designate if they want to handle these when they're caused by FileNotFoundException. The Throwable.getCause() seems a likely candidate. I'm not really suggesting a language revision, but to illustrate my point:


        try
        {
        myApi.go();
        }
        catch( MyApiException e whencausedby FileNotFoundException )
        {
        }
        /* otherwise, MyApiException isn't caught at all */
        finally
        {
        }
        • Daniel
           
          Posts: 5 / Nickname: dyokomiso / Registered: September 17, 2002 2:50 PM
          Re: The Trouble with Checked Exceptions
          August 19, 2003 4:59 AM      
          > A way of dynamically composing a hierarchy would help,
          > that way I can throw a single exception,
          > MyApiException, and clients can designate if
          > they want to handle these when they're caused by
          > FileNotFoundException. The
          > Throwable.getCause() seems a likely
          > candidate. I'm not really suggesting a language revision,
          > but to illustrate my point:
          >
          >
          > try
          > {
          > myApi.go();
          > }
          > catch( MyApiException e whencausedby FileNotFoundException
          > )
          > {
          > }
          > /* otherwise, MyApiException isn't caught at all */
          > finally
          > {
          > }
          >


          Some kind of generics can help here. If Exception was declared as having a generic cause parameter we could write (assuming Some<A> extends Some<B> if A extends B):


          try {
          myApi.go();
          } catch(MyApiException<FileNotFoundException> e) {
          } catch(MyApiException<IOException> e) {
          } finally {
          /* otherwise, MyApiException isn't caught at all */
          }
        • Ram
           
          Posts: 2 / Nickname: rama236 / Registered: August 18, 2003 3:08 PM
          Re: The Trouble with Checked Exceptions
          August 18, 2003 7:51 PM      
          Most of the time, the Exceptions are used as a means to convey an appropriate message (The cause for the abnormal behaviour) to the end user/client. The actual error message can be embedded into the Exception instance in the code block where Exception actually occurred. So that the client can display this message using the e.getMessage(). If the catch block should be doing something more than mere displaying of the message, then as Prescott pointed out, getCause() should be an appropriate candidate. But this concept of checked Exceptions cannot be avoided altogether. Atleast it ensures that some good developers would end up handling it :-) .
          • Andrew
             
            Posts: 2 / Nickname: methusaleh / Registered: February 14, 2003 10:40 PM
            Re: The Trouble with Checked Exceptions
            August 18, 2003 9:20 PM      
            Nowadays exceptions seem to have removed return values as a method of indicating success/failure or an unexpected event. (In some ways I guess its does this cleaner and simpler.) However I tend to restrict the use of exceptions for implementing 'exceptional use cases' and stick with return values to handle errors and such. Is it possible that people are just over using exceptions or using them for the wrong purposes? (Especially with respect to the versioning problems)
            • Noop
               
              Posts: 2 / Nickname: dleuck / Registered: October 2, 2003 6:45 PM
              Re: The Trouble with Checked Exceptions
              October 2, 2003 11:08 PM      
              > Nowadays exceptions seem to have removed return values as
              > a method of indicating success/failure or an unexpected
              > event. (In some ways I guess its does this cleaner and
              > simpler.) However I tend to restrict the use of
              > exceptions for implementing 'exceptional use cases' and
              > stick with return values to handle errors and such. Is it
              > possible that people are just over using exceptions or
              > using them for the wrong purposes? (Especially with
              > respect to the versioning problems)

              Returning errors is considered an antipattern. It is very bad design for a number of reasons (example - its easy for the programmer (API user) to accidentally handle the error as a an "answer" rather than an "error". Many famous computer disasters were caused by this practice. It has been generally agreed that signals (ex: Exceptions) should be used instead.
    • David
       
      Posts: 1 / Nickname: dav / Registered: August 26, 2003 1:58 AM
      The Trouble with C,C#,C++ newbie's
      August 26, 2003 8:38 AM      
      >"Adding a new exception to a throws clause in a new version breaks client code. "

      Adding a new exception to a throws clause doe NOT break client code(does not
      break binary compatibility).Its embarrassing that the interviewers/tech editors
      did not catch this.

      >"You don't want a program where in 100 different places you handle exceptions and pop up error dialogs. "
      ..."The exception handling should be centralized,"

      Refactorings/Design patterns can be used centralize exception handling.See:
      <a href="http://www.refactoring.com/catalog/extractMethod.html">Extract Method</a>
      or even use <a
      href="http://www.javaworld.com/javaworld/jw-04-2003/jw-0425-designpattern s.html">Simple Singleton</a> if you must.


      >"...people do ridiculous things. For example, they decorate every method with, "throws Exception...
      [OR]...You end up having to declare 40 exceptions that you might throw. "
      Forty exceptions in a throws clause? This interview is sounds more like a troll.

      "I can't tell you how many times I've seen this—they say, try, da da, catch curly curly."

      I have seen empty catch blocks in poorly written overly verbose intro to Java books.
      Where have you seen such awful code?


      Checked exceptions are one of the reasons why Java is better than C# -
      <a href="http://www.freeroller.net/page/ceperez/20030129?catname=101%20List">Re ason
      #64</a> Would rather rely on documentation than have the compiler let you know of a possible exception?

      "For example, lots of newbie's coming in from the C world complain about exceptions and the fact that they have to put exception handling all over the place - they want to just write their code. But that's stupid: most C code never checks return codes and so it tends to be very fragile. If you want to build something really robust, you need to pay attention to things that can go wrong and most folks don't in the C world because it's just to damn hard.
      One of the design principles behind Java is that I don't care much about how long it takes to slap together something that kinda works. The real measure is how long it takes to write something solid. Lots have studies have been done on developer productivity, and Java beats C and C++ by a factor of 2...."
      - <a href="http://weblogs.java.net/jag/">James Gosling</a>


      I'm a strong believer that if you don't have anything right to say, or anything that
      moves the art forward, then you'd better just be completely silent

      Here Here!!
      • Matt
         
        Posts: 62 / Nickname: matt / Registered: February 6, 2002 7:27 AM
        Re: The Trouble with C,C#,C++ newbie's
        August 26, 2003 11:05 AM      
        > Its embarrassing that the interviewers/tech editors
        did not catch this.

        Probably wasn't in the throws clause.
      • Frank
         
        Posts: 135 / Nickname: fsommers / Registered: January 19, 2002 7:24 AM
        Re: The Trouble with C,C#,C++ newbie's
        August 26, 2003 10:47 AM      
        > One of the design principles behind Java is that I don't
        > care much about how long it takes to slap together
        > something that kinda works. The real measure is how long
        > it takes to write something solid. ."
        > - <a href="http://weblogs.java.net/jag/">James
        > Gosling</a>

        I was not aware of this blog by Gosling, but it really speaks to the heart of the issue. I found this out when I moved from doing primarly consulting to building and shipping an end-user product. When you have a product to support, all the short-cuts, all the sloppiness, all the unwritten tests, etc., that you thought were OK in that late-night hour's moment of exhaustion - will come back to haunt you with a vengeance. It will take MUCH longer, and cost many times more, to have to come back and fix problems with a product that's in the customer's hands. In fact, that just might mean the difference whether a small firm can "swim across" (to paraphrase Andy Grove), or whether it will run out of steam mid-lake.

        Gosling's comment is what I think we should use as a benchmark when judging a programming language: How long it takes to create something robust with a given language. Since most programming languages are Turing-complete, you can pretty much use any language to write any program you wish. I used to think that I was productive with a language when I could quickly put something together that just sort of worked. But there is a difference between "sort of works" and "bet-my-money-on-it" works. Now I care much more about the latter than the former.
        • Matt
           
          Posts: 62 / Nickname: matt / Registered: February 6, 2002 7:27 AM
          Re: The Trouble with C,C#,C++ newbie's
          August 27, 2003 0:12 AM      
          > Gosling's comment is what I think we should use as a
          > benchmark when judging a programming language: How long it
          > takes to create something robust with a given language.
          > Since most programming languages are Turing-complete, you
          > can pretty much use any language to write any program you
          > wish. I used to think that I was productive with a
          > language when I could quickly put something together that
          > just sort of worked. But there is a difference between
          > "sort of works" and "bet-my-money-on-it" works. Now I care
          > much more about the latter than the former.

          But what evidence is there that Java programs are, on the average, more robust than programs in every other language, because of checked exceptions? It may be that this is a bit like the static vs. dynamic type language divide -- some people feel more comfortable with static types and think that such code must be more robust. I think you only get robust programs from hard work and extraordinary care, regardless of language features.
          • David
             
            Posts: 3 / Nickname: malven / Registered: July 2, 2003 2:32 PM
            Re: The Trouble with C,C#,C++ newbie's
            August 27, 2003 5:07 AM      
            > But what evidence is there that Java programs are,
            > on the average, more robust than programs in every other
            > language, because of checked exceptions?

            Who made that claim? I believe the discussion was whether or not checked exceptions contribute to higher-quality programs, not whether Java is the "best language ever" specifically because of this one feature.

            > I think you only get robust programs from hard
            > work and extraordinary care, regardless of language
            > features.

            I disagree. Of course, hard work and skill are necessary, but different language features can have a huge impact on the amount of skill required to get programs to work reliably. As an extreme example, with enough care you could write a huge multi-tier application in assembler, but few programmers could do so, and it would take an inordinate amount of time.

            I've been working in Java for over 8 years, and my experience with checked exceptions is that they are well worth the effort. Checked vs. unchecked was a huge debate when RMI was first released, because RemoteException was checked and many (including me) thought it shouldn't be. Jim Waldo, in particular, made a compelling case that it should remain checked, and many years later I'm glad he held his ground. In my view, the exceptions that a method can throw are as much a part of the contract as the value it returns.

            In practice, the "explosion of checked exceptions" problem cited in the original article rarely occurs, so I think it is a bit of a red herring. However, I have seen many Java systems where the designers decided they disliked checked exceptions and made everything extend RemoteException. Almost without exception (<g>) this was simply because they thought having to deal with checked exceptions was "a pain" (meaning inconvenient). And in many of those cases it was a sympton of sloppy design or sloppy error handling in general.
            • Noop
               
              Posts: 2 / Nickname: dleuck / Registered: October 2, 2003 6:45 PM
              Re: The Trouble with C,C#,C++ newbie's
              October 2, 2003 11:10 PM      
              > However, I have seen many Java systems where the
              > designers decided they disliked checked exceptions
              > and made everything extend RemoteException.

              I think you mean "RuntimeException"

              BTW - I agree with you 100%. Exceptions are an important part of the API contract.
              • Gregg
                 
                Posts: 28 / Nickname: greggwon / Registered: April 6, 2003 1:36 PM
                Re: The Trouble with C,C#,C++ newbie's
                October 3, 2003 8:49 PM      
                > > However, I have seen many Java systems where the
                > > designers decided they disliked checked exceptions
                > > and made everything extend RemoteException.
                >
                > I think you mean "RuntimeException"

                I am sure that he means RemoteException. It is a common thought in RMI programming that you've already sprinkled 'throws RMIException' at the end of all you methods in your Remote interface, so rather than add yet another Exception to that, just extend RemoteException, or wrap the exception in RemoteException.

                The modifications to add a cause to exceptions was brilliant. Calling initCause() with an Exception that you can't pass up the ladder makes it much easier to wrap your implementation in a well devised collection of Exceptions, and not loose any information about where the real problem occured at.

                Checked Exceptions are a vital part of any API that interfaces with something that the calling code has no control over. If I am opening a file, using the network, making and RPC call etc, it will be impossible for me to guarentee the outcome with software. Thus, the Exception tells me that something unexpected and impossible (a relative term without historical perspective) to deal with has occured, plain and simple.

                My initial thought when reading this piece was, wow, here's someone else who works for that company that is selling the software that is costing people the most time, money and agony (due to data loss). He thinks that handling exceptional cases is not that important, or at least not important enough to require rigor. Perhaps buffer overruns are not exceptional cases after all, and we should just consider them a part of life... and all the virui that have come from them?

                I too wonder about the conflict of this position versus the virtual method position...
                • Gregg
                   
                  Posts: 28 / Nickname: greggwon / Registered: April 6, 2003 1:36 PM
                  Changing Exceptions in the Life Cycle
                  October 6, 2003 2:12 PM      
                  I was thinking about this issue some more. One of the vital capabilites of Java is downloaded code. In Jini applications (and simple RMI too), you can easily exploit downloaded code to make changes to the API. As an example, consider an interface with a method that does work on the server. In the initial version, you just passed a key value to select the type of operation and the server did it locally and returned the result.

                  In the next version of the client, you want the server to also provide a proxy connect operation to some other machines for a new class of keys, and if it can't connect, the client needs to tell the user, or make some other decision. The important business is that if the old client doesn't (and can't because of implementation) pass the new keys, it can never see the new class of exceptions!

                  So, you need to add to the throws clause to include the exceptions that are associated with the remote work.
                  public interface MyInterface extends Remote {
                      public void meth1( String type ) throws RemoteException;
                  }
                  

                  is the old version of the interface and method. In the new version, you should make the changes in a backward compatible way. You can code this as
                  public interface MyInterface extends Remote {
                      public void meth1( String type ) throws RemoteException;
                      public void newMeth1( String type )throws IOException,IllegalArgumentException;
                  }
                  

                  Now, the next part is the tricky part. You want to make the server have this new functionality, but keep the client interface backward compatible with the old client.

                  So, you use the delegate pattern to create a smart proxy that allows the new server API to exist, but hides the old method and defers to the new method.

                  public class MyInterfaceSmartProxy implements MyInterface,java.io.Serializable {
                      MyInterface del;
                      public MyInterfaceSmartProxy( MyInterface delegate ) {
                          del = delegate;
                      }
                      public void meth1( String val ) throws RemoteException {
                          try {
                              del.newMeth1( val );
                          } catch( RemoteException ex ) {
                              throw ex;
                          } catch( IOException ex ) {
                              log.log( Level.SEVERE, ex.toString(), ex );
                          }
                      }
                  }
                  


                  Now, in the server, where you would normally register your proxy with the LUS or RMIRegistery, you would instead pass
                  new MyInterfaceSmartProxy( exportedObject ), where exportedObject was the existing proxy.

                  Now, you have a versioned solution and the user always gets the correct solution after the server is upgraded because you are exploiting downloaded code to manage versioning...
    • Dag
       
      Posts: 1 / Nickname: dag / Registered: August 18, 2003 5:00 PM
      Re: The Trouble with Checked Exceptions
      August 18, 2003 9:21 PM      
      Hello! Have we forgotton about semantic distances? I think anyone who suggests increasing it, should read The "Pragmatic Programmer: From journeyman to Master" or similar book.

      A error that is not handled where it occurs, is often not handled at all. This is especially true for programmers with a sloppy style of their art. Sloppy programmers, resistant to learning how to do it right, won't do error handling properly anyway.

      If exceptions are not handled locally, how does the main message loop get to know how to deal with exceptions, especially in the large systems case. A FileNotFound Exception might be innocent or it disastrous. Should the main message loop inspect the stack trace, and decide what to do?

      What if a subsystem is poorly implemented, (where throwing it out is not an option). Such subsystems act as snipers, and in programming languages without checked exceptions you will not have good chances to discover what errors/exceptions might be thrown before they blow up in your face production time.
      Systems with local try - catch curly curly, should not be reused at all: they will never behave in a larger perspective. This is bad bad programming, and is not worth struggling with.
      • Damon
         
        Posts: 1 / Nickname: doremon / Registered: February 7, 2004 9:24 PM
        Re: The Trouble with Checked Exceptions
        February 8, 2004 2:36 AM      
        I can't say I'm qualified as I don't do super big systems (thanked goodness). For small interactive applications, program throws an error, usually it's appropriate to just display it to the end-user.

        But let's say we have large concurrent systems. In some cases, the errors could be due to concurrent or unknown events that results in denial of certain resources. Due to business requirements (an example, last item in the online store but just got booked by a VIP whom may or may not want it, business rule says don't tell online shoppers that it's unavailable) or some jinx (e.g. weird network problem), application detect error at runtime but don't know the exact cause or can't reveal...what do you do?

        Throwing an exception may not be the important thing here but the finally part is (e.g. tell shopper that their other items are processed and ready for payment but not that last item due to whatever cook up reason). Well, i don't know the right answer for this as well....hmmmm, still pondering.
      • Vincent
         
        Posts: 40 / Nickname: vincent / Registered: November 13, 2002 7:25 AM
        Re: The Trouble with Checked Exceptions
        August 19, 2003 0:13 AM      
        > ...in programming languages without checked exceptions
        > you will not have good chances to discover what
        > errors/exceptions might be thrown before they blow up in
        > your face production time...

        This argument sounds almost identical to the one used against languages (such as Python) that don't use compile time type checking. That being the case, then the reposte will also be similar... test driven development, if done properly, should be as effective in dealing with unchecked exceptions as it is in dealing with untyped variables.

        Poor programmers will always cause problems. I don't think that you can design a system that deals with them efficiently but that's another story.

        Vince.
        • Benjamin
           
          Posts: 1 / Nickname: benthere / Registered: February 10, 2005 7:16 AM
          Re: The Trouble with Checked Exceptions
          March 19, 2006 1:11 PM      
          > This argument sounds almost identical to the one used
          > against languages (such as Python) that don't use compile
          > time type checking. That being the case, then the reposte
          > will also be similar... test driven development, if done
          > properly, should be as effective in dealing with unchecked
          > exceptions as it is in dealing with untyped variables.
          >
          > Poor programmers will always cause problems.

          This argument doesn't account for the fact that we will always have poor programmers. Each of us was, at one time, a 'poor' programmer (no matter how short we imagine our visit with this stage).

          The extent to which languages and tools coerce good practices with minimal negative impact to advanced programmers is particulary beneficial to the new-to-intermediate level programmer. In turn, this is beneficial to everyone who will inevitably have to fix a bug or hike through their ragged code path.
    • Matthew
       
      Posts: 1 / Nickname: darkfrog / Registered: February 10, 2004 5:51 AM
      Re: The Trouble with Checked Exceptions
      February 10, 2004 10:58 AM      
      After reading this article I can't help but wonder why you didn't state that checked exceptions are optional in Java? It is up the coder to decide if they want checked or unchecked Exceptions. If you extend RuntimeException it is automatically unchecked. For example, how many times have us Java coders had to deal with NullPointerExceptions, but never actually had to put a catch block in our code? It's just one example of an unchecked exception in Java. Granted, there are several checked exceptions in Java that you are required to deal with if you wish to use that Object, but the designer of that Object thought it necessary to deal with that exception. If you don't like it, create your own Object that does the same thing and use unchecked exceptions.

      As for this debate in general, I think it's laziness that makes people disagree with checked exceptions as a whole. They are an amazing feature and quite useful to a good programmer. I realize they are often abused, but that's the problem of bad coding rather than bad language implementation.

      Thanks,

      Matthew Hicks
      darkfrog@pyramex.com
      • Gregg
         
        Posts: 28 / Nickname: greggwon / Registered: April 6, 2003 1:36 PM
        Re: The Trouble with Checked Exceptions
        May 6, 2013 11:03 AM      
        The basic idea of Checked Exceptions, is that there are some things, in software system, which happen because of outside stimuli. I/O subsystems, for example can cause exceptional problems when networks fail, disks crash and many other things in related ways. In the case of I/O, you have a "context" related to that I/O, which controls how you react to the problem. Checked Exceptions are a good thing to announce to the software systems, that something has occurred, which will keep the software from accomplishing the task it has initiated, and the software CAN take action which can correct the condition.

        RuntimeExceptions in Java are about "system" or "software" errors, which will likely keep the software from working correctly. ArrayIndexOutOfBounds exceptions as well as the Error subclasses of Throwable, represent many common issues.

        The fact that C# has no checked exceptions, for me, is a cop-out on the problem. It means that they didn't spend time to really talk to experienced developers creating large software systems that run in a server environment, to understand how important it is for some software systems to "never-fail".

        Microsoft, historically, has lacked this expertise, and even today, some 10-years since this interview, the situation has not really changed. C# is still missing all kinds of important features for software stability and uptime, which Java continues to provide great benefits from having.