Introduction to Java Exception Handling

2010-09-21  来源:本站原创  分类:Java  人气:179 

http://tutorials.jenkov.com/java-exception-handling/index.html

A good java site

http://www.java-tips.org/java-se-tips/java.util.logging/how-to-log-an-exception.html

Exception handling is a very important yet often neglected aspect of writing robust software. When an error occurs in a Java program it usually results in an exception being thrown. How you throw, catch and handle these exception matters. There are several different ways to do so. Not all are equally efficient and fail safe.

This trail digs deeper into exception handling in Java. The trail covers various do's and dont's of Java exception handling. It also covers a few techniques for efficient and less error prone exception handling. Hopefully you can benefit from some of these texts.

Below follows a quick introduction to what you can learn in this Java exception handling trail.

Basic Java Exception Handling

The first 2 texts on Java exception handling covers the basics of Java's exception throwing and catching mechanism, and exception hierarchies. These texts are:

  • Basic Try Catch Finally
  • Exception Hierarchies

Checked vs. Unchecked Exceptions in Java

Java is one of the few languages to support both checked and unchecked exceptions. In the text Checked or Unchecked Exceptions? I discuss the difference between these two types of exceptions. I also end up recommending unchecked exceptions over checked exceptions.

General Java Exception Handling Advice

The middle 6 texts in this Java exception handling trail covers issues like "fail safe exception" handling, "where to log exceptions", advice on throwing exceptions during validation etc. In other words, various advice on what to remember when designing your application exception throwing and handling.

Advanced Exception Handling in Java

The two texts Exception Handling Templates and Exception Enrichment discusses two somewhat more advanced exception handling techniques that can clean up your code a bit. Exception templates moves all the "try-catch" code to one or more reusable exception handling templates. Exception enrichment rids you of having tons of different exceptions in your exception hierarchy. It also helps you avoid long exception stack traces, and get truly unique error codes for each error in your application.

Most Popular on Java Exception Handling

The most popular texts in this Java exception handling tutorial are the texts on Exception Handling Templates and Exception Enrichment.

Table of Contents for Java Exception Handling Tutorial

Below is a list of the texts this trail Java Exception Handling contains. The list is repeated at the top right of every page in the trail.

<! - <td Colspan="2"> <img src="/images/toc.png" alt="Table of Contents" /> </ td> ->

Java Exception Handling
Introduction to Java Exception Handling
Basic Try Catch Finally
Exception Hierarchies
Checked or Unchecked Exceptions?
Exception Wrapping
Fail Safe Exception Handling
Pluggable Exception Handlers
Logging: Where to Log Exceptions?
Validation: Throw Exceptions Early
Validation: Throw Exception or Return False?
Exception Handling Templates
Exception Enrichment
相关文章
  • Introduction to Java Exception Handling 2010-09-21

    http://tutorials.jenkov.com/java-exception-handling/index.html A good java site http://www.java-tips.org/java-se-tips/java.util.logging/how-to-log-an-exception.html Exception handling is a very important yet often neglected aspect of writing robust s

  • java exception handling 2010-03-29

    Exception handling is a very important program design aspect of the program design is a major difficulty, starting from the C, you may already know how to use if ... else ... to control abnormal, and may be spontaneous, but this kinds of abnormal pai

  • java exception handling mechanism (1) 2010-06-26

    Exception handling is a very important programming aspect of program design is a major difficulty, starting from C, you may already know how to use the if ... else ... to control abnormal, and may be spontaneous, but this kind of control the abnormal

  • java exception handling habits (reprint) 2010-10-12

    The bad habits of the six exception handling Do you think you are a Java expert? Sure that they have complete control of the Java exception handling mechanism? In the code below, you can quickly find out the exception handling of the six questions? O

  • java exception handling bad habits 2010-03-29

    Reprinted from: http://bbs.chinaitlab.com/thread-167286-1-2.html Do you think he is a Java specialists? Is it a must that he has complete control of the Java exception handling mechanism? 1 OutputStreamWriter out = ... 2 java.sql.Connection conn = ..

  • java exception handling framework 2010-04-02

    Transfer from http://www.bitscn.com/java/xmlbeans/200806/143914_4.html 1, unusual concepts and architecture of Java exceptions Exception is a procedural error during the operation. This article teaches the Java language exception handling. Java langu

  • java exception handling mechanism (2) 2010-06-26

    Fourth, how to define and use the exception classes 1, using the existing exception classes, if the IOException, SQLException. try ( Code ) Catch (IOException ioe) ( Code ) Catch (SQLException sqle) ( Code ) Finally ( Code ) 2, create a custom except

  • The general principles of Java exception handling 2010-09-05

    1) First, do not throw exception, that after the catch exception and do nothing. If you think not handle the exception, let it continue to spread, so that treatment to other places; or you can convert a low-level application-level exception exception

  • Efficient Java exception handling framework (change) 2010-09-26

    Abstract: This article from the most basic concepts of Java exceptions, the syntax of the Java exception handling began to talk about the basic knowledge of the Java exception architecture, compared to Spring's exception handling framework, expounds

  • Java exception handling mechanism (try, catch, finally) 2010-10-12

    First look at a piece of code: public class TCFtest { public TCFtest() { } @SuppressWarnings("finally") boolean testEx() throws Exception { boolean ret = true; try { ret = testEx1(); } catch (Exception e) { System.out.println("testEx, catch

  • Java exception handling of the bad habits of six 2010-12-12

    Do you think you are a Java expert? Sure that they have complete control of the Java exception handling mechanism? In the code below, you can quickly find out the exception handling of the six questions? 1 OutputStreamWriter out = ... 2 java.sql.Conn

  • Java exception handling and exception mechanism for introducing 2009-04-03

    When a program can not control the external environment (user provided file does not exist, the document is damaged, the network is not available ...) is, JAVA will be used to describe the exception object. JAVA approach using two kinds of exceptions

  • java exception handling experience 2010-07-07

    We know that there are two categories java abnormal one is check Exception, a kind of a runtime Exception. 1.check exception if a method throws check exception, the code calls the method either catch or throw the exception re-statement. 2. Runtime Ex

  • JAVA exception handling and analysis of the difference between 2010-11-05

    First, the inner method throws an exception, the outer methods to catch and handle the exception: public void methodA () { try { / / Call methodB methodB (); } catch (ExceptionType et) { / / The appropriate treatment measures } } public void methodB

  • Java exception handling efficiency 2011-01-12

    Java developers can make the most important decision-making framework is one of how to use the Java exception model. Java exception has always been the target of much controversy in the community. It has been argued that, in the Java language excepti

  • Exception Handling Templates in Java (java exception handling template) 2010-06-24

    Before you read this text, it is a good idea to have read the text "Fail Safe Exception Handling". Correct exception handling code can be tedious to write. Try-catch blocks also clutter the code and makes it harder to read. Look at the example b

  • Depth exploration of the Java exception handling framework and efficient 2010-11-11

    Suddenly remembered the application exception handling problem, before this knowledge is rarely used, or may not see a good application of the article, really be able to from the overall analysis, architecture, very exciting, especially the voice of

  • java exception handling mechanism 2011-04-27

    Primer try ... catch ... finally I am afraid that all too familiar statement, and it feels it is very simple to use, the logic seems easy to understand. However, I personally experience the "lessons" Tell me, this thing is not quite that simple,

  • Java's exception handling mechanism 2010-07-21

    Exception handling is a programming in a very important aspect of program design is a major difficulty, starting from C, you may already know how to use the if ... else ... to control abnormal, and may be spontaneous, but this kinds of abnormal pain

  • Java exception and error handling 1 2010-05-02

    SimpleExceptionDemo.java file package com.demo; public class SimpleExceptionDemo ( public static void main (String [] args) ( int a = 9; int b = 0; try ( System.out.println ("Java exception handling its own integrated"); new OperateDemo (). oper