0
|
1 |
// Copyright (c) 1994-2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
2 |
// All rights reserved.
|
|
3 |
// This component and the accompanying materials are made available
|
|
4 |
// under the terms of the License "Eclipse Public License v1.0"
|
|
5 |
// which accompanies this distribution, and is available
|
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
7 |
//
|
|
8 |
// Initial Contributors:
|
|
9 |
// Nokia Corporation - initial contribution.
|
|
10 |
//
|
|
11 |
// Contributors:
|
|
12 |
//
|
|
13 |
// Description:
|
|
14 |
// e32\euser\us_trp.cpp
|
|
15 |
//
|
|
16 |
//
|
|
17 |
|
|
18 |
#include "us_std.h"
|
|
19 |
#include "us_data.h"
|
|
20 |
|
|
21 |
|
|
22 |
|
|
23 |
|
|
24 |
EXPORT_C TTrapHandler::TTrapHandler()
|
|
25 |
/**
|
|
26 |
Default constructor.
|
|
27 |
*/
|
|
28 |
{}
|
|
29 |
|
|
30 |
|
|
31 |
#ifndef __LEAVE_EQUALS_THROW__
|
|
32 |
|
|
33 |
EXPORT_C void TTrap::UnTrap()
|
|
34 |
//
|
|
35 |
// Pop the current trap frame
|
|
36 |
//
|
|
37 |
{
|
|
38 |
|
|
39 |
TTrapHandler *pH=Exec::PopTrapFrame()->iHandler;
|
|
40 |
if (pH!=NULL)
|
|
41 |
pH->UnTrap();
|
|
42 |
}
|
|
43 |
|
|
44 |
|
|
45 |
#else //__LEAVE_EQUALS_THROW__
|
|
46 |
|
|
47 |
EXPORT_C void User::Leave(TInt aReason)
|
|
48 |
/**
|
|
49 |
Leaves the currently executing function, unwinds the call stack, and returns
|
|
50 |
from the most recently entered trap harness.
|
|
51 |
|
|
52 |
@param aReason The value returned from the most recent call to TRAP or TRAPD.
|
|
53 |
This is known as the reason code and, typically, it gives the
|
|
54 |
reason for the environment or user error causing this leave
|
|
55 |
to occur.
|
|
56 |
|
|
57 |
@see TRAP
|
|
58 |
@see TRAPD
|
|
59 |
*/
|
|
60 |
{
|
|
61 |
#ifdef __USERSIDE_THREAD_DATA__
|
|
62 |
Exec::LeaveStart();
|
|
63 |
TTrapHandler* pH = GetTrapHandler();
|
|
64 |
#else
|
|
65 |
TTrapHandler* pH = Exec::LeaveStart();
|
|
66 |
#endif
|
|
67 |
if (pH)
|
|
68 |
pH->Leave(aReason); // causes things on the cleanup stack to be cleaned up
|
|
69 |
throw XLeaveException(aReason);
|
|
70 |
}
|
|
71 |
|
|
72 |
#endif // !__LEAVE_EQUALS_THROW__
|
|
73 |
|
|
74 |
|
|
75 |
// Private declaration to prevent def file branching
|
|
76 |
#ifndef __SUPPORT_CPP_EXCEPTIONS__
|
|
77 |
class XLeaveException
|
|
78 |
{
|
|
79 |
public:
|
|
80 |
IMPORT_C TInt GetReason() const;
|
|
81 |
};
|
|
82 |
#endif //__SUPPORT_CPP_EXCEPTIONS__
|
|
83 |
|
|
84 |
#if !defined(__LEAVE_EQUALS_THROW__) || !defined(__WINS__)
|
|
85 |
EXPORT_C TInt XLeaveException::GetReason() const
|
|
86 |
{
|
|
87 |
#ifdef __SUPPORT_CPP_EXCEPTIONS__
|
|
88 |
Exec::LeaveEnd();
|
|
89 |
return iR;
|
|
90 |
#else // !__SUPPORT_CPP_EXCEPTIONS__
|
|
91 |
return KErrNone;
|
|
92 |
#endif //__SUPPORT_CPP_EXCEPTIONS__
|
|
93 |
}
|
|
94 |
#endif // !defined(__LEAVE_EQUALS_THROW__) || !defined(__WINS__)
|
|
95 |
|
|
96 |
EXPORT_C void User::LeaveNoMemory()
|
|
97 |
/**
|
|
98 |
Leaves with the specific reason code KErrNoMemory.
|
|
99 |
|
|
100 |
@see KErrNoMemory
|
|
101 |
*/
|
|
102 |
{
|
|
103 |
|
|
104 |
User::Leave(KErrNoMemory);
|
|
105 |
}
|
|
106 |
|
|
107 |
|
|
108 |
|
|
109 |
|
|
110 |
EXPORT_C TInt User::LeaveIfError(TInt aReason)
|
|
111 |
/**
|
|
112 |
Leaves or returns with a specified reason code.
|
|
113 |
|
|
114 |
If the reason code is negative the function leaves, and the reason code is
|
|
115 |
returned through the trap harness.
|
|
116 |
|
|
117 |
If the reason code is zero or positive, the function simply returns with the
|
|
118 |
reason value.
|
|
119 |
|
|
120 |
@param aReason The reason code.
|
|
121 |
|
|
122 |
@return If the function returns, the reason code which is either zero or positive.
|
|
123 |
*/
|
|
124 |
{
|
|
125 |
|
|
126 |
if (aReason<0)
|
|
127 |
User::Leave(aReason);
|
|
128 |
return(aReason);
|
|
129 |
}
|
|
130 |
|
|
131 |
|
|
132 |
|
|
133 |
|
|
134 |
EXPORT_C TAny * User::LeaveIfNull(TAny *aPtr)
|
|
135 |
/**
|
|
136 |
Leaves with the reason code KErrNoMemory, if the specified pointer is NULL.
|
|
137 |
|
|
138 |
If the pointer is not NULL, the function simply returns with the value of
|
|
139 |
the pointer.
|
|
140 |
|
|
141 |
@param aPtr The pointer to be tested.
|
|
142 |
|
|
143 |
@return If the function returns, the value of aPtr.
|
|
144 |
*/
|
|
145 |
{
|
|
146 |
|
|
147 |
if (aPtr==NULL)
|
|
148 |
User::LeaveNoMemory();
|
|
149 |
return(aPtr);
|
|
150 |
}
|
|
151 |
|