DESCRIPTION: Declaration of the classes: ErrorMessage ExceptionDescription Exception AccessError AssertionFailure DeviceError InvalidParameter InvalidRequest ResourceExhausted OutOfMemory OutOfSystemResource OutOfWindowResource
This file also contains many of the macros used to implement the library exception handling mechanism. This includes the UIMA_ASSERT, UIMA_EXC_THROW, UIMA_EXC_RETHROW, UIMA_EXC_CONTEXT, UIMA_EXCEPTION_DESCRIPTION, UIMA_EXC_CLASSDECLARE, UIMA_EXC_CLASSIMPLEMENT, macros.
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.
This file contains the base class for all exceptions used in UIMACPP project. The design goal was to allow for an easy way to provide rich context information with the exception without introducing the need to write lots of lines of code every time you use an exception.
The way this is accomplished here is by defining a rich exception class and then providing macros for its everyday use that hide its complexity and automate a lot of processes.
A UIMACPP exception has an error info object as its main informational member. Such an error info object containes a text, which is supposed to be a simple description of the error with out context (e.g. "Could not open file") an error number and an error severity (recoverable or unrecoverable). To this basic information a list of error contexts can be added (a context has a text and a location, see class ErrorContext
above). A context specifies what the program was trying to do, when the error occurred (e.g. "Trying to open file XYZ.ABC for reading") since very often not the whole context a user might need to understand the error is locally available the exception can be re-throw after adding a context. At the point where it is caught more context can be added and again it can be re-thrown until finally the exception can be taken care of (examined/displayed).
This process of defining/catching, adding context and then (re)throwing is what is very convenient to do via the macros defined below.
Namespaces | |
namespace | uima |
Classes | |
class | uima::ErrorMessage |
Class ErrorMessage: this is a helper class for main class ErrorInfo and ErrorContext . More... | |
class | uima::ErrorContext |
Class ErrorContext: this is a helper class for main class Exception . More... | |
class | uima::ErrorInfo |
Class ErrorInfo : This is the base class for all error information used in UIMACPP. More... | |
class | uima::Exception |
Class Exception: This is the base class for all exceptions used in UIMACPP group projects. More... | |
Predefined Exceptions (beginning of an error hierarchy). | |
The following predefined exceptions are supposed to structure the use of exceptions, help with avoiding multiple definitions of common exceptions (e.g.
file not found) and provide a start for an exception hierarchy. | |
UIMA_EXC_CLASSDECLARE (Uima_logic_error, Exception) | |
logic error | |
UIMA_EXC_CLASSDECLARE (Uima_runtime_error, Exception) | |
runtime error | |
UIMA_EXC_CLASSDECLARE (Uima_domain_error, Uima_logic_error) | |
domain error | |
UIMA_EXC_CLASSDECLARE (Uima_invalid_argument, Uima_logic_error) | |
invalid argument | |
UIMA_EXC_CLASSDECLARE (Uima_length_error, Uima_logic_error) | |
length error | |
UIMA_EXC_CLASSDECLARE (Uima_out_of_range, Uima_logic_error) | |
out of range | |
UIMA_EXC_CLASSDECLARE (Uima_range_error, Uima_runtime_error) | |
range error | |
UIMA_EXC_CLASSDECLARE (Uima_overflow_error, Uima_runtime_error) | |
overflow error | |
UIMA_EXC_CLASSDECLARE (Uima_underflow_error, Uima_runtime_error) | |
underflow error | |
UIMA_EXC_CLASSDECLARE (ConsoleAbortExc, Exception) | |
The following exceptions are used by helper test classes that are no longer in the UIMACPP library: CommandLineDriver DocBuffer ParseHandlers. | |
UIMA_EXC_CLASSDECLARE (ExcDocBuffer, Uima_out_of_range) | |
UIMA_EXC_CLASSDECLARE (ParseHandlerExc, Exception) | |
UIMA_EXC_CLASSDECLARE (ExcIllFormedInputError, Uima_runtime_error) | |
Ill formed input. | |
UIMA_EXC_CLASSDECLARE (ExcInvalidParameter, Uima_invalid_argument) | |
Invalid Parameter. | |
UIMA_EXC_CLASSDECLARE (ExcIndexOutOfRange, Uima_out_of_range) | |
Index out of Range. | |
UIMA_EXC_CLASSDECLARE (ExcInvalidRequest, Uima_runtime_error) | |
Invalid Request. | |
UIMA_EXC_CLASSDECLARE (ExcResourceExhausted, Uima_runtime_error) | |
Resource Exhausted. | |
UIMA_EXC_CLASSDECLARE (ExcOutOfMemory, ExcResourceExhausted) | |
Out of Memory. | |
UIMA_EXC_CLASSDECLARE (ExcFileNotFoundError, Uima_runtime_error) | |
File not Found. | |
UIMA_EXC_CLASSDECLARE (ExcWinCException, Uima_runtime_error) | |
UIMA_EXC_CLASSDECLARE (CodePageConversionException, Exception) | |
Used to report code page conversion errors. | |
Defines | |
#define | UIMA_MSG_MAX_STR_LEN 4096 |
#define | UIMA_MSG_REPLACE_CHAR '%' |
#define | EXCEPTION_BASE_CLASS std::exception |
Define for base class of Exception ANSI compliant STL implementations (newer compilers GNU etc.). | |
#define | UIMA_EXC_CONTEXT(cntxt) uima::ErrorContext((uima::ErrorMessage)(cntxt), __FILE__, 0, __LINE__) |
#define | UIMA_EXC_ADD_CONTEXT(exc, cntxt) exc.getErrorInfo().addContext(UIMA_EXC_CONTEXT((ErrorMessage)(cntxt))) |
This macro is intended to be used for adding context to exceptions. | |
#define | UIMA_EXC_THROW(exc, cntxt) |
This macro is intended to be used for throwing exceptions that are already defined. | |
#define | UIMA_EXC_RETHROW(exc, cntxt) |
This macro is intended to be used for re-throwing caught exceptions with added context. | |
#define | UIMA_EXC_THROW_NEW(exType, errorNbr, errorMsg, exContext, recoverable) |
This macro is intended to be used for throwing exceptions that are not yet defined. | |
#define | UIMA_EXC_ASSERT_EXCEPTION(test) |
#define | CHILD_DESTRUCT_THROW0() UIMA_THROW0() |
#define | UIMA_EXC_CLASSDECLARE(child, parent) |
This macro is intended to derive new exceptions from the base class (or an already derived exception class). | |
#define | UIMA_EXC_CLASSIMPLEMENT(child, parent) |
This macro is intended to derive new exceptions from the base class (or an already derived exception class). | |
Functions | |
std::ostream & | operator<< (std::ostream &rclOStream, const ErrorMessage &crclExceptionMessage) |
ErrorMessage output support for streams. | |
std::ostream & | operator<< (std::ostream &rclOStream, const ErrorContext &crclExceptionContext) |
ErrorContext output support for streams. | |
std::ostream & | operator<< (std::ostream &rclOStream, const ErrorInfo &crclErrorInfo) |
ErrorInfo output support for streams. | |
std::ostream & | operator<< (std::ostream &rclOStream, const Exception &crclException) |
Exception output support for streams. | |
UIMA_EXC_CLASSDECLARE (AprFailureException, Exception) | |
The following exception is used to report failures from APR functions. |
|
|
|
|
|
Define for base class of Exception ANSI compliant STL implementations (newer compilers GNU etc.).
|
|
|
|
This macro is intended to be used for adding context to exceptions.
It adds a the contexts
|
|
Value: exc.getErrorInfo().addContext(UIMA_EXC_CONTEXT(cntxt)),\ exc.logExceptionData(),\ throw(exc)
It adds a the contexts string
|
|
Value: exc.getErrorInfo().addContext(UIMA_EXC_CONTEXT(cntxt)),\ exc.logExceptionData(),\ throw exc
It adds a the contexts string
|
|
Value: exType exc(errorMsg, errorNbr, recoverable); \ UIMA_EXC_THROW(exc, exContext)
It defines an exception of type
|
|
|
|
|
|
Value: /*lint -save -e1932 -e1901 -e1931 -e754 -e19 */ \ class UIMA_LINK_IMPORTSPEC child : public parent { \ public: \ child ( \ uima::ErrorMessage clMessage, \ uima::TyErrorId ulErrorId, \ uima::ErrorInfo::EnSeverity enSeverity = uima::ErrorInfo::unrecoverable \ ); \ child ( \ uima::ErrorInfo clErrInfo \ ); \ virtual const char* getName() const; \ virtual ~child() CHILD_DESTRUCT_THROW0(); \ child (const child &); \ private: \ child &operator = ( const child & ); \ }
This will typically be used in .h/.hpp files. For each use of
|
|
Value: /*lint -save -e1901 -e1911 -e1746 -e1917 -e1902 */ \ child :: child ( \ uima::ErrorMessage clMessage, \ uima::TyErrorId ulErrorId, \ uima::ErrorInfo::EnSeverity enSeverity \ ) \ : parent (clMessage, ulErrorId, enSeverity) \ {;} \ child :: child ( \ uima::ErrorInfo clInfo \ ) \ : parent (clInfo) \ {;} \ const char* child :: getName() const { \ return ( # child); \ } \ child :: ~ child () CHILD_DESTRUCT_THROW0() {;} \ child::child (const child & a) : parent (a) {;} \
This will typically be used in .c/.cpp files. For each use of
|
|
Assuming your message is Trying to load function begindoc. |
|
This will first stream out the message part of the context and then (indented by spaces) the file name, function name and line number info (if present). This means you will typically get a multi-line text!
If Trying to load function begindoc. In debug mode it will look like: Trying to load function begindoc.
File : extract.cpp
Function: ExternalAnnotator::tryGetProcAddress(char*)
Line : 87
|
|
This will stream out:
If Recoverable : No Error number : -1 Error : Cannot find function address in DLL/library While : Trying to load function begindoc While : Trying to load Annotator IXTalent Test While : Trying to initialize UIMACPP. In debug mode it will look like: Error number : -1
Recoverable : No
Error : Cannot find function address in DLL/library
While : Trying to load function begindoc
File : extract.cpp
Function: ExternalAnnotator::tryGetProcAddress(char*)
Line : 87
While : Trying to load Annotator IXTalent Test
File : extracts.cpp
Function: Annotators::init(AnnotatorsConfig&)
Line : 116
While : Trying to initialize UIMACPP.
File : framewrk.cpp
Function: Framework::init(const IString&)
Line : 128
|
|
This will stream out:
If Exception : AnnotatorException Error number : -1 Recoverable : No Error : Cannot find function address in DLL/library While : Trying to load function begindoc While : Trying to load Annotator IXTalent Test While : Trying to initialize UIMACPP. In debug mode it will look like: Exception : AnnotatorException
Error number : -1
Recoverable : No
Error : Cannot find function address in DLL/library
While : Trying to load function begindoc
File : extract.cpp
Function: ExternalAnnotator::tryGetProcAddress(char*)
Line : 87
While : Trying to load Annotator IXTalent Test
File : extracts.cpp
Function: Annotators::init(AnnotatorsConfig&)
Line : 116
While : Trying to initialize UIMACPP.
File : framewrk.cpp
Function: Framework::init(const IString&)
Line : 128
|
|
logic error This is the reason why they have the "unconventional" names: Uima_<ansi name> |
|
runtime error
|
|
domain error
|
|
invalid argument
|
|
length error
|
|
out of range
|
|
range error
|
|
overflow error
|
|
underflow error
|
|
The following exceptions are used by helper test classes that are no longer in the UIMACPP library: CommandLineDriver DocBuffer ParseHandlers.
|
|
|
|
|
|
Ill formed input.
|
|
Invalid Parameter.
|
|
Index out of Range.
|
|
Invalid Request.
|
|
Resource Exhausted.
|
|
Out of Memory.
|
|
File not Found.
|
|
|
|
Used to report code page conversion errors.
|
|
The following exception is used to report failures from APR functions.
|