|
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 "Symbian Foundation License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.symbianfoundation.org/legal/sfl-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 #ifndef __TOOLS2__ |
|
63 Exec::LeaveStart(); |
|
64 #endif |
|
65 TTrapHandler* pH = GetTrapHandler(); |
|
66 #else |
|
67 TTrapHandler* pH = Exec::LeaveStart(); |
|
68 #endif |
|
69 if (pH) |
|
70 pH->Leave(aReason); // causes things on the cleanup stack to be cleaned up |
|
71 throw XLeaveException(aReason); |
|
72 } |
|
73 |
|
74 #endif // !__LEAVE_EQUALS_THROW__ |
|
75 |
|
76 |
|
77 // Private declaration to prevent def file branching |
|
78 #ifndef __SUPPORT_CPP_EXCEPTIONS__ |
|
79 class XLeaveException |
|
80 { |
|
81 public: |
|
82 IMPORT_C TInt GetReason() const; |
|
83 }; |
|
84 #endif //__SUPPORT_CPP_EXCEPTIONS__ |
|
85 |
|
86 #if !defined(__LEAVE_EQUALS_THROW__) || !defined(__WINS__) |
|
87 EXPORT_C TInt XLeaveException::GetReason() const |
|
88 { |
|
89 #ifdef __SUPPORT_CPP_EXCEPTIONS__ |
|
90 #ifndef __TOOLS2__ |
|
91 Exec::LeaveEnd(); |
|
92 #endif |
|
93 return iR; |
|
94 #else // !__SUPPORT_CPP_EXCEPTIONS__ |
|
95 return KErrNone; |
|
96 #endif //__SUPPORT_CPP_EXCEPTIONS__ |
|
97 } |
|
98 #endif // !defined(__LEAVE_EQUALS_THROW__) || !defined(__WINS__) |
|
99 |
|
100 EXPORT_C void User::LeaveNoMemory() |
|
101 /** |
|
102 Leaves with the specific reason code KErrNoMemory. |
|
103 |
|
104 @see KErrNoMemory |
|
105 */ |
|
106 { |
|
107 |
|
108 User::Leave(KErrNoMemory); |
|
109 } |
|
110 |
|
111 |
|
112 |
|
113 |
|
114 EXPORT_C TInt User::LeaveIfError(TInt aReason) |
|
115 /** |
|
116 Leaves or returns with a specified reason code. |
|
117 |
|
118 If the reason code is negative the function leaves, and the reason code is |
|
119 returned through the trap harness. |
|
120 |
|
121 If the reason code is zero or positive, the function simply returns with the |
|
122 reason value. |
|
123 |
|
124 @param aReason The reason code. |
|
125 |
|
126 @return If the function returns, the reason code which is either zero or positive. |
|
127 */ |
|
128 { |
|
129 |
|
130 if (aReason<0) |
|
131 User::Leave(aReason); |
|
132 return(aReason); |
|
133 } |
|
134 |
|
135 |
|
136 |
|
137 |
|
138 EXPORT_C TAny * User::LeaveIfNull(TAny *aPtr) |
|
139 /** |
|
140 Leaves with the reason code KErrNoMemory, if the specified pointer is NULL. |
|
141 |
|
142 If the pointer is not NULL, the function simply returns with the value of |
|
143 the pointer. |
|
144 |
|
145 @param aPtr The pointer to be tested. |
|
146 |
|
147 @return If the function returns, the value of aPtr. |
|
148 */ |
|
149 { |
|
150 |
|
151 if (aPtr==NULL) |
|
152 User::LeaveNoMemory(); |
|
153 return(aPtr); |
|
154 } |
|
155 |