1
0
Fork 0
cl-sites/guile.html_node/Exceptions-and-C.html
2024-12-17 12:49:28 +01:00

120 lines
7 KiB
HTML

<!DOCTYPE html>
<html>
<!-- Created by GNU Texinfo 7.1, https://www.gnu.org/software/texinfo/ -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<!-- This manual documents Guile version 3.0.10.
Copyright (C) 1996-1997, 2000-2005, 2009-2023 Free Software Foundation,
Inc.
Copyright (C) 2021 Maxime Devos
Copyright (C) 2024 Tomas Volf
Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License, Version 1.3 or
any later version published by the Free Software Foundation; with no
Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A
copy of the license is included in the section entitled "GNU Free
Documentation License." -->
<title>Exceptions and C (Guile Reference Manual)</title>
<meta name="description" content="Exceptions and C (Guile Reference Manual)">
<meta name="keywords" content="Exceptions and C (Guile Reference Manual)">
<meta name="resource-type" content="document">
<meta name="distribution" content="global">
<meta name="Generator" content=".texi2any-real">
<meta name="viewport" content="width=device-width,initial-scale=1">
<link href="index.html" rel="start" title="Top">
<link href="Concept-Index.html" rel="index" title="Concept Index">
<link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
<link href="Exceptions.html" rel="up" title="Exceptions">
<link href="Throw-and-Catch.html" rel="prev" title="Throw and Catch">
<style type="text/css">
<!--
a.copiable-link {visibility: hidden; text-decoration: none; line-height: 0em}
div.example {margin-left: 3.2em}
span:hover a.copiable-link {visibility: visible}
strong.def-name {font-family: monospace; font-weight: bold; font-size: larger}
-->
</style>
<link rel="stylesheet" type="text/css" href="https://www.gnu.org/software/gnulib/manual.css">
</head>
<body lang="en">
<div class="subsubsection-level-extent" id="Exceptions-and-C">
<div class="nav-panel">
<p>
Previous: <a href="Throw-and-Catch.html" accesskey="p" rel="prev">Throw and Catch</a>, Up: <a href="Exceptions.html" accesskey="u" rel="up">Exceptions</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Concept-Index.html" title="Index" rel="index">Index</a>]</p>
</div>
<hr>
<h4 class="subsubsection" id="Exceptions-and-C-1"><span>6.11.8.4 Exceptions and C<a class="copiable-link" href="#Exceptions-and-C-1"> &para;</a></span></h4>
<p>There are some specific versions of Guile&rsquo;s original <code class="code">catch</code> and
<code class="code">with-throw-handler</code> exception-handling primitives that are still
widely used in C code.
</p>
<dl class="first-deftypefn">
<dt class="deftypefn" id="index-scm_005fc_005fcatch"><span class="category-def">C Function: </span><span><code class="def-type">SCM</code> <strong class="def-name">scm_c_catch</strong> <code class="def-code-arguments">(SCM tag, scm_t_catch_body body, void *body_data, scm_t_catch_handler handler, void *handler_data, scm_t_catch_handler pre_unwind_handler, void *pre_unwind_handler_data)</code><a class="copiable-link" href="#index-scm_005fc_005fcatch"> &para;</a></span></dt>
<dt class="deftypefnx def-cmd-deftypefn" id="index-scm_005finternal_005fcatch"><span class="category-def">C Function: </span><span><code class="def-type">SCM</code> <strong class="def-name">scm_internal_catch</strong> <code class="def-code-arguments">(SCM tag, scm_t_catch_body body, void *body_data, scm_t_catch_handler handler, void *handler_data)</code><a class="copiable-link" href="#index-scm_005finternal_005fcatch"> &para;</a></span></dt>
<dd><p>The above <code class="code">scm_catch_with_pre_unwind_handler</code> and <code class="code">scm_catch</code>
take Scheme procedures as body and handler arguments.
<code class="code">scm_c_catch</code> and <code class="code">scm_internal_catch</code> are equivalents taking
C functions.
</p>
<p><var class="var">body</var> is called as <code class="code"><var class="var">body</var> (<var class="var">body_data</var>)</code> with a catch
on exceptions of the given <var class="var">tag</var> type. If an exception is caught,
<var class="var">pre_unwind_handler</var> and <var class="var">handler</var> are called as
<code class="code"><var class="var">handler</var> (<var class="var">handler_data</var>, <var class="var">key</var>, <var class="var">args</var>)</code>.
<var class="var">key</var> and <var class="var">args</var> are the <code class="code">SCM</code> key and argument list from
the <code class="code">throw</code>.
</p>
<a class="index-entry-id" id="index-scm_005ft_005fcatch_005fbody"></a>
<a class="index-entry-id" id="index-scm_005ft_005fcatch_005fhandler"></a>
<p><var class="var">body</var> and <var class="var">handler</var> should have the following prototypes.
<code class="code">scm_t_catch_body</code> and <code class="code">scm_t_catch_handler</code> are pointer
typedefs for these.
</p>
<div class="example">
<pre class="example-preformatted">SCM body (void *data);
SCM handler (void *data, SCM key, SCM args);
</pre></div>
<p>The <var class="var">body_data</var> and <var class="var">handler_data</var> parameters are passed to
the respective calls so an application can communicate extra
information to those functions.
</p>
<p>If the data consists of an <code class="code">SCM</code> object, care should be taken that
it isn&rsquo;t garbage collected while still required. If the <code class="code">SCM</code> is a
local C variable, one way to protect it is to pass a pointer to that
variable as the data parameter, since the C compiler will then know the
value must be held on the stack. Another way is to use
<code class="code">scm_remember_upto_here_1</code> (see <a class="pxref" href="Foreign-Object-Memory-Management.html">Foreign Object Memory Management</a>).
</p></dd></dl>
<dl class="first-deftypefn">
<dt class="deftypefn" id="index-scm_005fc_005fwith_005fthrow_005fhandler"><span class="category-def">C Function: </span><span><code class="def-type">SCM</code> <strong class="def-name">scm_c_with_throw_handler</strong> <code class="def-code-arguments">(SCM tag, scm_t_catch_body body, void *body_data, scm_t_catch_handler handler, void *handler_data, int lazy_catch_p)</code><a class="copiable-link" href="#index-scm_005fc_005fwith_005fthrow_005fhandler"> &para;</a></span></dt>
<dd><p>The above <code class="code">scm_with_throw_handler</code> takes Scheme procedures as body
(thunk) and handler arguments. <code class="code">scm_c_with_throw_handler</code> is an
equivalent taking C functions. See <code class="code">scm_c_catch</code>
(see <a class="pxref" href="#Exceptions-and-C">Exceptions and C</a>) for a description of the parameters, the
behavior however of course follows <code class="code">with-throw-handler</code>.
</p></dd></dl>
</div>
<hr>
<div class="nav-panel">
<p>
Previous: <a href="Throw-and-Catch.html">Throw and Catch</a>, Up: <a href="Exceptions.html">Exceptions</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Concept-Index.html" title="Index" rel="index">Index</a>]</p>
</div>
</body>
</html>