diff options
authorJames Bursa <>2004-05-19 13:21:57 +0000
committerJames Bursa <>2004-05-19 13:21:57 +0000
commitd4928a03164ac503974af23254d53886b41ea2bf (patch)
parent82982c0b9f162c063a95930a39a9dc5e0065ccec (diff)
[project @ 2004-05-19 13:21:57 by bursa]
Add Error Handling section. svn path=/import/netsurf/; revision=867
1 files changed, 34 insertions, 0 deletions
diff --git a/Docs/developer b/Docs/developer
index 70dfac5c9..e366f3aef 100644
--- a/Docs/developer
+++ b/Docs/developer
@@ -177,4 +177,38 @@ white-space was pre, and to replace spaces with hard spaces for nowrap.
Additionally, calculate_inline_container_widths() was changed to give the
appropriate minimum width for pre and nowrap.
+\section errorhandling Error handling
+This section gives some suggestions for error handling in the code.
+The most common serious error is memory exhaustion. Previously we used xcalloc()
+etc. instead of malloc(), so that no recovery code was required, and NetSurf
+would just exit. We should no longer use this. If malloc(), strdup(), etc.
+fails, clean up and free any partially complete structures leaving data in a
+consistent state, and return a value which indicates failure, eg. 0 for
+functions which return a pointer (document the value in the function
+documentation). The caller should then propagate the failure up in the same way.
+At some point, the error should stop being passed up and be reported to the user
+warn_user("NoMemory", 0);
+The other common error is one returned by a RISC OS SWI. Always use "X" SWIs,
+something like this:
+os_error *error;
+error = xwimp_get_pointer_info(&pointer);
+if (error) {
+ LOG(("xwimp_get_pointer_info: 0x%x: %s\n",
+ error->errnum, error->errmess));
+ warn_user("WimpError", error->errmess);
+ return false;
+If an error occurs during initialisation, in most cases exit immediately using
+die(), since this indicates that there is already insufficient memory, or a
+resource file is corrupted, etc.