[latexila] try/catch for resources_lookup_data()
- From: SÃbastien Wilmet <swilmet src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [latexila] try/catch for resources_lookup_data()
- Date: Fri, 4 May 2012 17:03:27 +0000 (UTC)
commit c78934aeb225fdf1ef43efbab258c759e5613749
Author: SÃbastien Wilmet <swilmet src gnome org>
Date: Thu May 3 21:18:08 2012 +0200
try/catch for resources_lookup_data()
src/symbols.vala | 9 ++++++---
src/utils.vala | 15 ++++++++++++---
2 files changed, 18 insertions(+), 6 deletions(-)
---
diff --git a/src/symbols.vala b/src/symbols.vala
index fbc4c00..c8d4542 100644
--- a/src/symbols.vala
+++ b/src/symbols.vala
@@ -192,11 +192,14 @@ private class NormalSymbols : ListStore
private void load_symbols ()
{
+ unowned string? contents =
+ Utils.get_string_from_resource (_resource_path + "data.xml");
+
+ if (contents == null)
+ return;
+
try
{
- unowned string contents =
- Utils.get_string_from_resource (_resource_path + "data.xml");
-
MarkupParser parser = { parser_start, null, null, null, null };
MarkupParseContext context = new MarkupParseContext (parser, 0, this, null);
context.parse (contents, -1);
diff --git a/src/utils.vala b/src/utils.vala
index d959ab5..4cb06b8 100644
--- a/src/utils.vala
+++ b/src/utils.vala
@@ -75,10 +75,19 @@ namespace Utils
return true;
}
- public unowned string get_string_from_resource (string resource_path)
+ public unowned string? get_string_from_resource (string resource_path)
{
- Bytes bytes = resources_lookup_data (resource_path, 0);
- return (string) bytes.get_data ();
+ try
+ {
+ Bytes bytes = resources_lookup_data (resource_path, 0);
+ return (string) bytes.get_data ();
+ }
+ catch (Error e)
+ {
+ warning ("Failed to load data from resource '%s': %s",
+ resource_path, e.message);
+ return null;
+ }
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]