Computable-Error-Messages.html 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <html lang="en">
  2. <head>
  3. <title>Computable Error Messages - avram - a virtual machine code interpreter</title>
  4. <meta http-equiv="Content-Type" content="text/html">
  5. <meta name="description" content="avram - a virtual machine code interpreter">
  6. <meta name="generator" content="makeinfo 4.13">
  7. <link title="Top" rel="start" href="index.html#Top">
  8. <link rel="up" href="Exception-Handling.html#Exception-Handling" title="Exception Handling">
  9. <link rel="prev" href="Expedient-Error-Messages.html#Expedient-Error-Messages" title="Expedient Error Messages">
  10. <link rel="next" href="Exception-Handler-Usage.html#Exception-Handler-Usage" title="Exception Handler Usage">
  11. <link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage">
  12. <meta http-equiv="Content-Style-Type" content="text/css">
  13. <style type="text/css"><!--
  14. pre.display { font-family:inherit }
  15. pre.format { font-family:inherit }
  16. pre.smalldisplay { font-family:inherit; font-size:smaller }
  17. pre.smallformat { font-family:inherit; font-size:smaller }
  18. pre.smallexample { font-size:smaller }
  19. pre.smalllisp { font-size:smaller }
  20. span.sc { font-variant:small-caps }
  21. span.roman { font-family:serif; font-weight:normal; }
  22. span.sansserif { font-family:sans-serif; font-weight:normal; }
  23. --></style>
  24. </head>
  25. <body>
  26. <div class="node">
  27. <a name="Computable-Error-Messages"></a>
  28. <p>
  29. Next:&nbsp;<a rel="next" accesskey="n" href="Exception-Handler-Usage.html#Exception-Handler-Usage">Exception Handler Usage</a>,
  30. Previous:&nbsp;<a rel="previous" accesskey="p" href="Expedient-Error-Messages.html#Expedient-Error-Messages">Expedient Error Messages</a>,
  31. Up:&nbsp;<a rel="up" accesskey="u" href="Exception-Handling.html#Exception-Handling">Exception Handling</a>
  32. <hr>
  33. </div>
  34. <h5 class="subsubsection">2.7.15.5 Computable Error Messages</h5>
  35. <p>The automatic generation and reporting of error messages provides a
  36. reasonable default behavior for applications that do not consider
  37. exceptional conditions. All applications and their input data are
  38. ordinarily members of the bottom level set in the hierarchy
  39. (<a href="A-Hierarchy-of-Sets.html#A-Hierarchy-of-Sets">A Hierarchy of Sets</a>). The error messages caused by invalid
  40. operations on this level are on the first level above the bottom, which
  41. are recognized as such and written to standard error without
  42. intervention from the application. However, there are two drawbacks to
  43. this style of dealing with exceptions.
  44. <a name="index-exceptions-368"></a>
  45. <ul>
  46. <li>An application developer may wish to translate error messages
  47. into terms that are meaningful to the user, not only by literally
  48. translating them from English to the local vernacular, but perhaps by
  49. relating the particular exceptional condition to application specific
  50. causes. While it is convenient for the &ldquo;back end&rdquo; code not to be
  51. required to intervene in the error reporting, it would be most
  52. inconvenient for it not to be able to do so.
  53. <li>Some application specific errors might not correspond directly to any of
  54. the particular conditions detected automatically due to invalid
  55. operations, for example a semantic error in a syntactically correct
  56. input file. It might be convenient in such cases for an application to
  57. be able to define its own error messages but still have them reported
  58. automatically like the built in messages.
  59. </ul>
  60. <p>These situations suggest a need for some ability on the part of an
  61. application to operate on error messages themselves. Based on the
  62. operator semantics given so far, such an application is inexpressible,
  63. because for any application <var>f</var><code>_0</code> and error message
  64. <var>x</var><code>_1</code><!-- /@w -->, property <em>P44</em> stipulates <var>f</var><code>_0 </code><var>x</var><code>_1</code> =
  65. <var>x</var><code>_1</code>, meaning that the resulting error message is
  66. unchanged. Therefore, we need to define another basic property of the
  67. operator.
  68. <p>The following form of virtual code is used in applications that may need
  69. to operate on error messages.
  70. <a name="index-g_t_0040code_007bguard_007d-369"></a>
  71. <dl>
  72. <dt><em>T32</em><dd>[[<code>guard</code>]] <code>(</code><var>f</var><code>,</code><var>g</var><code>)</code> = <code>((nil,</code><var>f</var><code>),</code><var>g</var><code>)</code>
  73. </dl>
  74. <p class="noindent">Code in this form has the following semantics.
  75. <dl>
  76. <dt><em>P53</em><dd>([[<code>guard</code>]] <code>(</code><var>f</var><code>,</code><var>g</var><code>)</code>)<code>_</code><var>n</var>
  77. <var>x</var><code>_</code><var>p</var> =
  78. <var>g</var><code>_(</code><var>n</var><code>+1) </code><var>f</var><code>_</code><var>n</var> <var>x</var><code>_</code><var>p</var>
  79. </dl>
  80. <p class="noindent">The intuitive explanation is that <var>f</var> is the main part of the
  81. application, and <var>g</var> is the part of the application that
  82. operates on the error message that comes from <var>f</var> if an
  83. exception occurs while it is being evaluated (i.e., the &ldquo;exception
  84. handler&rdquo;). Typically the exception handler code implements a function
  85. that takes an error message as an argument and returns an error message
  86. as a result.
  87. <p>Where there is no exception, the exception handler
  88. <var>g</var><code>_(</code><var>n</var><code>+1)</code> is never used, because its argument will be
  89. on level <var>n</var>, and therefore unaffected by an application on
  90. level <var>n</var><code>+1</code>.
  91. <p>Exception handlers may have their own exception handlers, which will be
  92. invoked if the evaluation of the exception handler causes a further
  93. exception. Such an exception corresponds semantically to a value on the
  94. next level of the hierarchy of sets.
  95. </body></html>