Changeset 2878 for pjproject/trunk/pjlib/src/pjlib-test/exception.c
- Timestamp:
- Aug 14, 2009 10:41:00 AM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjlib/src/pjlib-test/exception.c
r2407 r2878 62 62 PJ_THROW( ID_2 ); 63 63 PJ_UNREACHED(return -1;) 64 } 65 66 static int try_catch_test(void) 67 { 68 PJ_USE_EXCEPTION; 69 int rc = -200; 70 71 PJ_TRY { 72 PJ_THROW(ID_1); 73 } 74 PJ_CATCH_ANY { 75 rc = 0; 76 } 77 PJ_END; 78 return rc; 79 } 80 81 static int throw_in_handler(void) 82 { 83 PJ_USE_EXCEPTION; 84 int rc = 0; 85 86 PJ_TRY { 87 PJ_THROW(ID_1); 88 } 89 PJ_CATCH_ANY { 90 if (PJ_GET_EXCEPTION() != ID_1) 91 rc = -300; 92 else 93 PJ_THROW(ID_2); 94 } 95 PJ_END; 96 return rc; 97 } 98 99 static int return_in_handler(void) 100 { 101 PJ_USE_EXCEPTION; 102 103 PJ_TRY { 104 PJ_THROW(ID_1); 105 } 106 PJ_CATCH_ANY { 107 return 0; 108 } 109 PJ_END; 110 return -400; 64 111 } 65 112 … … 154 201 return rc; 155 202 203 /* 204 * Nested handlers 205 */ 206 PJ_TRY { 207 rc = try_catch_test(); 208 } 209 PJ_CATCH_ANY { 210 rc = -70; 211 } 212 PJ_END; 213 214 if (rc != 0) 215 return rc; 216 217 /* 218 * Throwing exception inside handler 219 */ 220 rc = -80; 221 PJ_TRY { 222 int rc2; 223 rc2 = throw_in_handler(); 224 if (rc2) 225 rc = rc2; 226 } 227 PJ_CATCH_ANY { 228 if (PJ_GET_EXCEPTION() == ID_2) { 229 rc = 0; 230 } else { 231 rc = -90; 232 } 233 } 234 PJ_END; 235 236 if (rc != 0) 237 return rc; 238 239 240 /* 241 * Return from handler. Returning from the function inside a handler 242 * should be okay (though returning from the function inside the 243 * PJ_TRY block IS NOT OKAY!!). We want to test to see if handler 244 * is cleaned up properly, but not sure how to do this. 245 */ 246 PJ_TRY { 247 int rc2; 248 rc2 = return_in_handler(); 249 if (rc2) 250 rc = rc2; 251 } 252 PJ_CATCH_ANY { 253 rc = -100; 254 } 255 PJ_END; 256 257 156 258 return 0; 157 259 }
Note: See TracChangeset
for help on using the changeset viewer.