Content deleted Content added
m →Visual Prolog: <ref> |
m clean up |
||
Line 6:
=== Ada ===
{{Further
{{Wikibooks|Ada Programming|Exceptions}}
Line 44:
=== Assembly language ===
{{Further
Most assembly languages will have a macro instruction or an interrupt address available for the particular system to intercept events such as illegal op codes, program check, data errors, overflow, divide by zero, and other such. IBM and Univac mainframes had the [[STXIT]] macro. Digital Equipment Corporation [[RT11]] systems had trap vectors for program errors, i/o interrupts, and such. [[DOS]] has certain interrupt addresses. [[Microsoft Windows]] has specific module calls to trap program errors.
=== Bash ===
{{Further
<syntaxhighlight lang="bash">
Line 69:
=== BASIC ===
{{Further
An ''On Error goto/gosub'' structure is used in BASIC and is quite different from modern exception handling; in BASIC there is only one global handler whereas in modern exception handling, exception handlers are stacked.
Line 85:
=== C ===
{{Further
C does not provide direct support to exception handling: it is the programmer's responsibility to prevent errors in the first place and test return values from the functions.
Line 120:
==== Microsoft-specific ====
{{Further
Two types exist:
* Structured Exception Handling (SEH)
Line 152:
=== C# ===
{{Further
A <code>try</code> block must have at least one <code>catch</code> or <code>finally</code> clause and at most one <code>finally</code> clause.
<syntaxhighlight lang="csharp">
Line 184:
=== C++ ===
{{Further
<syntaxhighlight lang="cpp">
#include <exception>
Line 203:
=== ColdFusion Markup Language (CFML) ===
{{Further
==== Script syntax ====
Line 244:
==== Railo-Lucee specific syntax ====
{{Further
Added to the standard syntax above, CFML dialects of [[Railo]] and [[Lucee]] allow a <code>retry</code> statement.<ref>https://issues.jboss.org/browse/RAILO-2176 # JBoss Community issue tracker ticket for adding <code>retry</code></ref>
This statement returns processing to the start of the prior <code>try</code> block.
Line 252:
<syntaxhighlight lang="javascript">
try {
// code which could result in an exception
} catch (any e){
Line 272:
=== D ===
{{Further
<syntaxhighlight lang="d">
import std.stdio; // for writefln()
Line 293:
=== Delphi ===
{{Further
; Exception declarations
<syntaxhighlight lang="delphi">
Line 309:
raise Exception.Create('Message');
raise Exception.CreateFmt('Message with values: %d, %d',[value1, value2]); // See SysUtils.Format() for parameters.
raise ECustom.CreateCustom(X);
Line 342:
=== Erlang ===
{{Further
<syntaxhighlight lang="erlang">
try
Line 356:
=== F# ===
{{Further
In addition to the OCaml-based <code>try...with</code>, F# also has the separate <code>try...finally</code> construct, which has the same behavior as a try block with a <code>finally</code> clause in other .NET languages.
Line 393:
=== Haskell ===
{{Further
Haskell does not have special syntax for exceptions. Instead, a {{Haskell|try}}/{{Haskell|catch}}/{{Haskell|finally}}/{{Haskell|etc}}. interface is provided by functions.
Line 442:
=== Java ===
{{Further
{{Wikibooks|Java Programming|Exceptions}}
A <code>try</code> block must have at least one <code>catch</code> or <code>finally</code> clause and at most one <code>finally</code> clause.
Line 459:
=== JavaScript ===
{{Further
The design of JavaScript makes loud/hard errors very uncommon. [[
<syntaxhighlight lang="javascript">
try {
Line 564:
=== Lisp ===
{{Further
==== Common Lisp ====
{{Further
<syntaxhighlight lang="lisp">
(ignore-errors (/ 1 0))
Line 585:
=== Lua ===
{{Further
Lua uses the <code>pcall</code> and <code>xpcall</code> functions, with <code>xpcall</code> taking a function to act as a <code>catch</code> block.
; Predefined function
Line 636:
=== Next Generation Shell ===
{{Further
; Defining custom exception type
Line 684:
=== Objective-C ===
{{Further
; Exception declarations
<syntaxhighlight lang="objc">
Line 723:
=== OCaml ===
{{Further
<syntaxhighlight lang="ocaml">
exception MyException of string * int (* exceptions can carry a value *)
Line 743:
=== Perl 5===
{{Further
The [[Perl]] mechanism for exception handling uses {{Perl2|die}} to throw an exception when wrapped inside an {{Perl2|eval { ... };}} block. After the {{Perl2|eval}}, the special variable {{Perl2|$@}} contains the value passed from {{Perl2|die}}.
Line 783:
The forms shown above can sometimes fail if the global variable {{Perl2|$@}} is changed between when the exception is thrown and when it is checked in the {{Perl2|if ($@)}} statement. This can happen in multi-threaded environments, or even in single-threaded environments when other code (typically
called in the destruction of some object) resets the global variable before the checking code.
The following example shows a way to avoid this problem (see [http://www.perlfoundation.org/perl5/index.cgi?exception_handling]{{
<syntaxhighlight lang="perl">
Line 801:
=== PHP ===
{{Further
<syntaxhighlight lang="php">
// Exception handling is only available in PHP versions 5 and greater.
Line 817:
=== PowerBuilder ===
{{Further
Exception handling is available in PowerBuilder versions 8.0 and above.
Line 831:
=== PowerShell ===
{{Further
==== Version 1.0 ====
Line 859:
=== Python ===
{{Further
<syntaxhighlight lang="python">
f = None
Line 877:
=== R ===
{{Further
<syntaxhighlight lang="splus">
tryCatch({
Line 895:
=== Rebol ===
{{Further
<syntaxhighlight lang="rebol">
REBOL [
Line 925:
=== Rexx ===
{{Further
<syntaxhighlight lang="rexx">
signal on halt;
Line 939:
=== Ruby ===
{{Further
<syntaxhighlight lang="ruby">
begin
Line 961:
=== S-Lang ===
{{Further
try
Line 985:
=== Smalltalk ===
{{Further
<syntaxhighlight lang="smalltalk">
[ "code that might throw an exception" ]
Line 995:
=== Swift ===
{{Further
Exception handling is supported since Swift 2.
<syntaxhighlight lang="swift">
Line 1,015:
=== Tcl ===
{{Further
<syntaxhighlight lang="tcl">
if { [ catch {
Line 1,041:
=== VBScript ===
{{Further
<syntaxhighlight lang="vbnet">
With New Try: On Error Resume Next
Line 1,093:
=== Visual Basic 6 ===
{{Further
Exception handling syntax is very similar to Basic. Error handling is local on each procedure.
<syntaxhighlight lang="vbnet">
Line 1,178:
==== Visual Basic .NET ====
{{Further
A <code>Try</code> block must have at least one clause <code>Catch</code> or <code>Finally</code> clause and at most one <code>Finally</code> clause.
<syntaxhighlight lang="vbnet">
Line 1,199:
=== Visual Prolog ===
{{Further
<syntaxhighlight lang="prolog">
Line 1,212:
=== X++ ===
{{Further
<syntaxhighlight lang="java">
public static void Main(Args _args)
|