From 39f88395bcef3aa972d48b31d4561c3c8a284d37 Mon Sep 17 00:00:00 2001 From: Jeroen Demeyer Date: Wed, 8 Jul 2015 18:04:35 +0200 Subject: [PATCH] Fix exception handling --- src/sage/graphs/chrompoly.pyx | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/sage/graphs/chrompoly.pyx b/src/sage/graphs/chrompoly.pyx index bfc1e9eec23..1df71ffd485 100644 --- a/src/sage/graphs/chrompoly.pyx +++ b/src/sage/graphs/chrompoly.pyx @@ -158,12 +158,14 @@ def chromatic_polynomial(G, return_tree_basis = False): i -= 1 try: sig_on() - contract_and_count(chords1, chords2, num_chords, nverts, tot, parent) - sig_off() - except RuntimeError: - for i from 0 <= i <= nverts: + try: + contract_and_count(chords1, chords2, num_chords, nverts, tot, parent) + finally: + sig_off() + except BaseException: + for i in range(nverts): mpz_clear(tot[i]) - raise RuntimeError("Error allocating memory for chrompoly.") + raise for i from 0 <= i <= nverts: mpz_init(coeffs[i]) # also sets them to 0 mpz_init(coeff)