選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

ErrorHandler.java 3.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /*
  2. Copyright (c) 2008 Health Market Science, Inc.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. package com.healthmarketscience.jackcess.util;
  14. import java.io.IOException;
  15. import com.healthmarketscience.jackcess.Column;
  16. import com.healthmarketscience.jackcess.Table;
  17. /**
  18. * Handler for errors encountered while reading a column of row data from a
  19. * Table. An instance of this class may be configured at the Database, Table,
  20. * or Cursor level to customize error handling as desired. The default
  21. * instance used is {@link #DEFAULT}, which just rethrows any exceptions
  22. * encountered.
  23. *
  24. * @author James Ahlborn
  25. * @usage _intermediate_class_
  26. */
  27. public interface ErrorHandler
  28. {
  29. /**
  30. * default error handler used if none provided (just rethrows exception)
  31. * @usage _general_field_
  32. */
  33. public static final ErrorHandler DEFAULT = new ErrorHandler() {
  34. @Override
  35. public Object handleRowError(Column column, byte[] columnData,
  36. Location location, Exception error)
  37. throws IOException
  38. {
  39. // really can only be RuntimeException or IOException
  40. if(error instanceof IOException) {
  41. throw (IOException)error;
  42. }
  43. throw (RuntimeException)error;
  44. }
  45. };
  46. /**
  47. * Handles an error encountered while reading a column of data from a Table
  48. * row. Handler may either throw an exception (which will be propagated
  49. * back to the caller) or return a replacement for this row's column value
  50. * (in which case the row will continue to be read normally).
  51. *
  52. * @param column the info for the column being read
  53. * @param columnData the actual column data for the column being read (which
  54. * may be {@code null} depending on when the exception
  55. * was thrown during the reading process)
  56. * @param location the current location of the error
  57. * @param error the error that was encountered
  58. *
  59. * @return replacement for this row's column
  60. */
  61. public Object handleRowError(Column column,
  62. byte[] columnData,
  63. Location location,
  64. Exception error)
  65. throws IOException;
  66. /**
  67. * Provides location information for an error.
  68. */
  69. public interface Location
  70. {
  71. /**
  72. * @return the table in which the error occurred
  73. */
  74. public Table getTable();
  75. /**
  76. * Contains details about the errored row, useful for debugging.
  77. */
  78. @Override
  79. public String toString();
  80. }
  81. }