[aisleriot] Use catch handler when loading the game code
- From: Christian Persch <chpe src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [aisleriot] Use catch handler when loading the game code
- Date: Thu, 14 Apr 2011 13:19:37 +0000 (UTC)
commit 1e334ced6bbcb132e333110c6157deaa5b76af84
Author: Christian Persch <chpe gnome org>
Date: Thu Apr 14 15:19:23 2011 +0200
Use catch handler when loading the game code
src/game.c | 29 +++++++++++++++++------------
1 files changed, 17 insertions(+), 12 deletions(-)
---
diff --git a/src/game.c b/src/game.c
index 58b74b0..0f67b59 100644
--- a/src/game.c
+++ b/src/game.c
@@ -1110,11 +1110,10 @@ cscmi_eval_installed_file (const char *filename,
GError **error)
{
char *path;
+ GError *err = NULL;
g_return_val_if_fail (filename != NULL, FALSE);
- /* FIXMEchpe: install exception handlers and set error if an exception occurs while loading the file? */
-
if (!g_str_has_suffix (filename, ".scm")) {
g_set_error (error, AISLERIOT_GAME_ERROR, GAME_ERROR_GENERIC,
"%s is not a scheme file", filename);
@@ -1122,20 +1121,26 @@ cscmi_eval_installed_file (const char *filename,
}
path = ar_runtime_get_file (AR_RUNTIME_GAMES_DIRECTORY, filename);
- if (g_file_test (path, G_FILE_TEST_EXISTS) &&
- g_file_test (path, G_FILE_TEST_IS_REGULAR)) {
- scm_c_primitive_load (path);
- g_free (path);
- return TRUE;
+ if (!g_file_test (path, G_FILE_TEST_EXISTS) ||
+ !g_file_test (path, G_FILE_TEST_IS_REGULAR)) {
+ g_set_error (error, AISLERIOT_GAME_ERROR, GAME_ERROR_GENERIC,
+ _("Aisleriot cannot load the file â??%sâ??. "
+ "Please check your Aisleriot installation."),
+ path);
+ return FALSE;
}
- g_set_error (error, AISLERIOT_GAME_ERROR, GAME_ERROR_GENERIC,
- _("Aisleriot cannot load the file â??%sâ??. "
- "Please check your Aisleriot installation."),
- path);
+ scm_c_catch (SCM_BOOL_T,
+ (scm_t_catch_body) scm_c_primitive_load, (void *) path,
+ game_scm_catch_handler, NULL,
+ game_scm_pre_unwind_handler, &err);
g_free (path);
+ if (err) {
+ g_propagate_error (error, err);
+ return FALSE;
+ }
- return FALSE;
+ return TRUE;
}
/* Class implementation */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]