• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* ------------------------------------------------------------------
2  * Copyright (C) 1998-2009 PacketVideo
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
13  * express or implied.
14  * See the License for the specific language governing permissions
15  * and limitations under the License.
16  * -------------------------------------------------------------------
17  */
18 // -*- c++ -*-
19 // = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
20 
21 //                     O S C L _ E X C E P T I O N
22 
23 // = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
24 
25 /*! \addtogroup osclerror OSCL Error
26  *
27  * @{
28  */
29 
30 
31 /** \file oscl_exception.h
32     \brief contains all the exception handling macros and classes
33 */
34 
35 
36 #ifndef OSCL_EXCEPTION_H_INCLUDED
37 #define OSCL_EXCEPTION_H_INCLUDED
38 
39 // - - Inclusion - - - - - - - - - - - - - - - - - - - - - - - - - - - -
40 
41 #ifndef OSCL_ERROR_H_INCLUDED
42 #include "oscl_error.h"
43 #endif
44 
45 #ifndef OSCL_ERROR_IMP_H_INCLUDED
46 #include "oscl_error_imp.h"
47 #endif
48 
49 
50 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
51 
52 //! oscl_exception.h contains all the exception handling macros and classes
53 
54 
55 //! This template class provides the base exception class that all exceptions derive from
56 /*!
57    All PacketVideo exception classes will be derived from the OsclException class.
58    Each derived class will have a static function where the leave code
59    can be obtained. This avoids the issue of having static members in a DLL.
60    The function needs to be static so it can be called without an instance
61    of the class
62 */
63 template <int LeaveCode> class OsclException
64 {
65     public:
OsclException()66         OsclException() {}
getLeaveCode()67         static int getLeaveCode()
68         {
69             return LeaveCode;
70         };
71 };
72 
73 
74 //! Use this macro to cause a Leave. It terminates the execution of the current active function
75 /*!
76     It also tries to cleanup the items on the cleanup stack.
77    \param oscl_leave_status tells the cause for the Leave
78 */
79 #define OSCL_LEAVE(_leave_status) OsclError::Leave(_leave_status)
80 
81 
82 //! This macro will be used to set up a try block
83 /*!
84    The try block identifies a block of code that might throw exceptions
85    (or leave)
86    \param oscl_leave_status oscl_leave_status will receive the result of any
87    OSCL_LEAVE (which will get called from a OSCL_THROW) on systems that do not
88    support exception handling.This is unused on systems that do support
89    exception handling
90    \param statements is a statement or block of statements that could throw
91    exceptions and will be executed in the try block
92 */
93 #define OSCL_TRY(_leave_status,_statements) _PV_TRAP(_leave_status,_statements)
94 //Same as above, but avoids the TLS lookup.
95 // param __trampimp is the OsclErrorTrapImp* for the current thread.
96 #define OSCL_TRY_NO_TLS(__trapimp,_leave_status,_statements) _PV_TRAP_NO_TLS(__trapimp,_leave_status,_statements)
97 
98 //! This section defines the macros to be used in the catch block following the try block
99 
100 //! Use this macro to call a function that handles all exception types thrown in the preceding try block
101 /*!
102    \param _leave_status
103    \param _statements is a statement or block of statements that will
104    catch all the exception types thrown by the preceding try block
105    This is a standalone macro and should not be used with any of the macros above
106 */
107 #define OSCL_FIRST_CATCH_ANY(_leave_status, _statements) \
108    if (_leave_status!=OsclErrNone) { _statements; }
109 
110 //! Use this macro to define a block of code that catches the first exception type thrown in the preceding try block
111 /*!
112    \param oscl_leave_status is the leave code that was returned by OSCL_THROW
113    \param exceptiontype is the exception handled by this catch block
114    This macro MUST be used in conjunction with either OSCL_LAST_CATCH or OSCL_CATCH_ANY
115 */
116 #define OSCL_FIRST_CATCH( _leave_status, _catch_value, _statements) \
117     if (_leave_status!=OsclErrNone && _leave_status == _catch_value){_statements;}
118 
119 //! Use this macro to define a block of code for catching additional exception types
120 /*!
121    OSCL_FIRST_CATCH can be used to catch one exception type. Then the
122    OSCL_CATCH macro can be used to catch each subsequent type. The catch
123    block must end with OSCL_LAST_CATCH or OSCL_CATCH_ANY
124    \param oscl_leave_status is the result of any OSCL_THROW
125    \param exceptiontype is the exception handled by this catch block
126 */
127 #define OSCL_CATCH( _leave_status, _catch_value, _statements) \
128     else if (_leave_status!=OsclErrNone && _leave_status == _catch_value){_statements;}
129 
130 //! Use this macro to call a function that will catch all remaining exception types
131 /*!
132    \param _leave_status
133    \param _statements is a statement or block of statements to
134    handle all remaining exception types.
135    This macro ends the try block.
136 */
137 #define OSCL_CATCH_ANY(_leave_status,_statements) \
138     else if (_leave_status!=OsclErrNone){ _statements;}
139 
140 //! Use this macro if OSCL_CATCH_ANY has not been used. It will mark the end of the catch block
141 /*!
142    \param _leave_status will be propagated up the call stack
143    This macro will do an OSCL_LEAVE if the leave has not been handled by the calls above.
144    This macro ends the try block.
145 */
146 
147 #define OSCL_LAST_CATCH(_leave_status) \
148     else if (_leave_status!=OsclErrNone){OSCL_LEAVE(_leave_status);}
149 
150 
151 #endif // INCLUDED_OSCL_EXCEPTION_H
152 
153 
154 
155 /*! @} */
156