mirror of
				https://github.com/Z3Prover/z3
				synced 2025-11-03 21:09:11 +00:00 
			
		
		
		
	moderate exception behavior for issue #861
Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
This commit is contained in:
		
							parent
							
								
									447c97a783
								
							
						
					
					
						commit
						e9edcdc6e6
					
				
					 1 changed files with 21 additions and 6 deletions
				
			
		| 
						 | 
				
			
			@ -345,7 +345,7 @@ namespace z3 {
 | 
			
		|||
        object(context & c):m_ctx(&c) {}
 | 
			
		||||
        object(object const & s):m_ctx(s.m_ctx) {}
 | 
			
		||||
        context & ctx() const { return *m_ctx; }
 | 
			
		||||
        void check_error() const { m_ctx->check_error(); }
 | 
			
		||||
        Z3_error_code check_error() const { return m_ctx->check_error(); }
 | 
			
		||||
        friend void check_context(object const & a, object const & b);
 | 
			
		||||
    };
 | 
			
		||||
    inline void check_context(object const & a, object const & b) { assert(a.m_ctx == b.m_ctx); }
 | 
			
		||||
| 
						 | 
				
			
			@ -688,11 +688,17 @@ namespace z3 {
 | 
			
		|||
           \brief Return int value of numeral, throw if result cannot fit in
 | 
			
		||||
           machine int
 | 
			
		||||
 | 
			
		||||
           It only makes sense to use this function if the caller can ensure that
 | 
			
		||||
           the result is an integer or if exceptions are enabled. 
 | 
			
		||||
           If exceptions are disabled, then use the the is_numeral_i function.
 | 
			
		||||
           
 | 
			
		||||
           \pre is_numeral()
 | 
			
		||||
        */
 | 
			
		||||
        int get_numeral_int() const {             
 | 
			
		||||
            int result = 0;
 | 
			
		||||
            if (!is_numeral_i(result) && ctx().enable_exceptions()) {
 | 
			
		||||
            if (!is_numeral_i(result)) {
 | 
			
		||||
                assert(ctx().enable_exceptions());
 | 
			
		||||
                if (!ctx().enable_exceptions()) return 0;
 | 
			
		||||
                throw exception("numeral does not fit in machine int");
 | 
			
		||||
            }
 | 
			
		||||
            return result;
 | 
			
		||||
| 
						 | 
				
			
			@ -702,12 +708,17 @@ namespace z3 {
 | 
			
		|||
           \brief Return uint value of numeral, throw if result cannot fit in
 | 
			
		||||
           machine uint
 | 
			
		||||
 | 
			
		||||
           It only makes sense to use this function if the caller can ensure that
 | 
			
		||||
           the result is an integer or if exceptions are enabled. 
 | 
			
		||||
           If exceptions are disabled, then use the the is_numeral_u function.           
 | 
			
		||||
           \pre is_numeral()
 | 
			
		||||
        */
 | 
			
		||||
        unsigned get_numeral_uint() const {
 | 
			
		||||
            assert(is_numeral());
 | 
			
		||||
            unsigned result = 0;
 | 
			
		||||
            if (!is_numeral_u(result) && ctx().enable_exceptions()) {
 | 
			
		||||
            if (!is_numeral_u(result)) {
 | 
			
		||||
                assert(ctx().enable_exceptions());
 | 
			
		||||
                if (!ctx().enable_exceptions()) return 0;
 | 
			
		||||
                throw exception("numeral does not fit in machine uint");
 | 
			
		||||
            }
 | 
			
		||||
            return result;
 | 
			
		||||
| 
						 | 
				
			
			@ -722,7 +733,9 @@ namespace z3 {
 | 
			
		|||
        __int64 get_numeral_int64() const {
 | 
			
		||||
            assert(is_numeral());
 | 
			
		||||
            __int64 result = 0;
 | 
			
		||||
            if (!is_numeral_i64(result) && ctx().enable_exceptions()) {
 | 
			
		||||
            if (!is_numeral_i64(result)) {
 | 
			
		||||
                assert(ctx().enable_exceptions());
 | 
			
		||||
                if (!ctx().enable_exceptions()) return 0;
 | 
			
		||||
                throw exception("numeral does not fit in machine __int64");
 | 
			
		||||
            }
 | 
			
		||||
            return result;
 | 
			
		||||
| 
						 | 
				
			
			@ -737,7 +750,9 @@ namespace z3 {
 | 
			
		|||
        __uint64 get_numeral_uint64() const {
 | 
			
		||||
            assert(is_numeral());
 | 
			
		||||
            __uint64 result = 0;
 | 
			
		||||
            if (!is_numeral_u64(result) && ctx().enable_exceptions()) {
 | 
			
		||||
            if (!is_numeral_u64(result)) {
 | 
			
		||||
                assert(ctx().enable_exceptions());
 | 
			
		||||
                if (!ctx().enable_exceptions()) return 0;
 | 
			
		||||
                throw exception("numeral does not fit in machine __uint64");
 | 
			
		||||
            }
 | 
			
		||||
            return result;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue