<?xml version="1.0"?>
<!--
 Licensed to the Apache Software Foundation (ASF) under one
 or more contributor license agreements.  See the NOTICE file
 distributed with this work for additional information
 regarding copyright ownership.  The ASF licenses this file
 to you under the Apache License, Version 2.0 (the
 "License"); you may not use this file except in compliance
 with the License.  You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

 Unless required by applicable law or agreed to in writing,
 software distributed under the License is distributed on an
 "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 KIND, either express or implied.  See the License for the
 specific language governing permissions and limitations
 under the License.
-->

<document>

 <properties>
   <title>Torque Runtime Reference - Exception handling</title>
 </properties>

 <body>

  <section name="Exception handling">
  
    <p>
      Torque converts all Exceptions thrown by the Database into 
      instances of <code>org.apache.torque.TorqueException</code>
      or subclasses thereof. TorqueException is a checked exception.
    </p>
    <p>
      Subclasses of TorqueException whcih are generated by database exceptions
      are:
    </p>
    <ul>
      <li>
        <code>org.apache.torque.ConstraintViolationException</code>
        - thrown whenever a write operation violates a unique key,
        a not-null constraint or a foreign key constraint in the database.
      </li>
      <li>
        <code>org.apache.torque.DeadlockEception</code>
        - thrown whenever the database detects a deadlock between two
        or more transaction which are executed simultaneously (Note: hsqldb
        does not seem to be able to detect deadlocks as of version 2.2.8).
      </li>
    </ul>
    <p>
      All other database exceptions are mapped to TorqueException directly.
    </p>
    <p>
      Torque also can throw TorqueExceptions or subclasses thereof 
      without a database error, e.g. if a database is accessed via Torque 
      when Torque is not initialized.
      Subclasses of TorqueExceptions thrown in special situations are:
    </p>
    <ul>
      <li>
        <code>org.apache.torque.NoRowsException</code>
        - thrown whenever a read operation expects to hit exactly one record
        but does not hit one (e.g. the generated retrieveByPk methods 
        in the generated peer classes). 
      </li>
      <li>
        <code>org.apache.torque.TooManyRowsException</code>
        - thrown whenever a read operation expects to hit at most one record
        but does hit more than one (e.g. by the doSelectSingleRecord methods
        in the peer classes). 
      </li>
    </ul>
  </section>
 </body>
</document>
