Merge pull request #1187 from devsisters/json-internal-catch
[RFC] Introduce a new macro function: JSON_INTERNAL_CATCH
This commit is contained in:
		
						commit
						0e748f2f8c
					
				
					 4 changed files with 20 additions and 4 deletions
				
			
		|  | @ -42,10 +42,12 @@ | |||
|     #define JSON_THROW(exception) throw exception | ||||
|     #define JSON_TRY try | ||||
|     #define JSON_CATCH(exception) catch(exception) | ||||
|     #define JSON_INTERNAL_CATCH(exception) catch(exception) | ||||
| #else | ||||
|     #define JSON_THROW(exception) std::abort() | ||||
|     #define JSON_TRY if(true) | ||||
|     #define JSON_CATCH(exception) if(false) | ||||
|     #define JSON_INTERNAL_CATCH(exception) if(false) | ||||
| #endif | ||||
| 
 | ||||
| // override exception macros
 | ||||
|  | @ -60,6 +62,11 @@ | |||
| #if defined(JSON_CATCH_USER) | ||||
|     #undef JSON_CATCH | ||||
|     #define JSON_CATCH JSON_CATCH_USER | ||||
|     #define JSON_INTERNAL_CATCH JSON_CATCH_USER | ||||
| #endif | ||||
| #if defined(JSON_INTERNAL_CATCH_USER) | ||||
|     #undef JSON_INTERNAL_CATCH | ||||
|     #define JSON_INTERNAL_CATCH JSON_INTERNAL_CATCH_USER | ||||
| #endif | ||||
| 
 | ||||
| // manual branch prediction
 | ||||
|  |  | |||
|  | @ -9,6 +9,7 @@ | |||
| #endif | ||||
| 
 | ||||
| // clean up
 | ||||
| #undef JSON_INTERNAL_CATCH | ||||
| #undef JSON_CATCH | ||||
| #undef JSON_THROW | ||||
| #undef JSON_TRY | ||||
|  |  | |||
|  | @ -3437,7 +3437,7 @@ class basic_json | |||
|             { | ||||
|                 return ptr.get_checked(this); | ||||
|             } | ||||
|             JSON_CATCH (out_of_range&) | ||||
|             JSON_INTERNAL_CATCH (out_of_range&) | ||||
|             { | ||||
|                 return default_value; | ||||
|             } | ||||
|  | @ -7359,7 +7359,7 @@ class basic_json | |||
|                         // the "path" location must exist - use at()
 | ||||
|                         success = (result.at(ptr) == get_value("test", "value", false)); | ||||
|                     } | ||||
|                     JSON_CATCH (out_of_range&) | ||||
|                     JSON_INTERNAL_CATCH (out_of_range&) | ||||
|                     { | ||||
|                         // ignore out of range errors: success remains false
 | ||||
|                     } | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue