[vala] Check for unhandled errors in creation methods



commit 973cced2ad48408d2edc481931706d39c952b93e
Author: Jürg Billeter <j bitron ch>
Date:   Sat Aug 15 15:50:08 2009 +0200

    Check for unhandled errors in creation methods
    
    Fixes bug 571973.

 vala/valacreationmethod.vala |   15 +++++++++++++++
 1 files changed, 15 insertions(+), 0 deletions(-)
---
diff --git a/vala/valacreationmethod.vala b/vala/valacreationmethod.vala
index 8700b05..3dc1aec 100644
--- a/vala/valacreationmethod.vala
+++ b/vala/valacreationmethod.vala
@@ -178,6 +178,21 @@ public class Vala.CreationMethod : Method {
 			return false;
 		}
 
+		// check that all errors that can be thrown in the method body are declared
+		if (body != null) {
+			foreach (DataType body_error_type in body.get_error_types ()) {
+				bool can_propagate_error = false;
+				foreach (DataType method_error_type in get_error_types ()) {
+					if (body_error_type.compatible (method_error_type)) {
+						can_propagate_error = true;
+					}
+				}
+				if (!can_propagate_error) {
+					Report.warning (body_error_type.source_reference, "unhandled error `%s'".printf (body_error_type.to_string()));
+				}
+			}
+		}
+
 		return !error;
 	}
 }



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]