Exception handling syntax: Difference between revisions

Content deleted Content added
Dylwi (talk | contribs)
add exception handling syntax for ooRexx
Tags: Reverted Visual edit
No edit summary
Tags: Mobile edit Mobile app edit iOS app edit App section source
 
(4 intermediate revisions by 2 users not shown)
Line 207:
try {
// do something (might throw an exception)
} catch (const std::runtime_error e) {
// handle a runtime_error e
} catch (const std::exception& e) {
// handlecatches exceptionall exceptions as e
} catch (...) {
// catches all exceptionsthrown types (including primitives or objects that do nit extend exception), not already caught by a catch block before
// can be used to catch exception of unknown or irrelevant type
}
}
Line 268 ⟶ 269:
try {
// code which could result in an exception
 
} catch (any e){
retry;
Line 493:
// Statements in which exceptions might be thrown
throw new Error("error");
} catch (error) {
// Statements that execute in the event of an exception
} finally {
Line 511:
try {
throw 12345; // primitive number
} catch (error) {
console.log(error); // logs 12345 as a primitive number to the console
}
Line 520:
// Example in Java
try {
Integer i = null;
i.intValue(); // throws a NullPointerException
} catch (NullPointerException error) {
// Variable might be null
} catch (ArithmeticException error) {
// Handle problems with numbers
}
</syntaxhighlight>
Line 534:
var example = null;
example.toString();
} catch (error) {
if (error.type === "TypeError") {
// Variable might be null
Line 549:
var example = null;
example.toString();
} catch (error) {
if (error.type !== "TypeError") throw error;
// Variable might be null
}
} catch (error) {
if (error.type !== "RangeError") throw error;
// Handle problems with numbers
Line 586:
obj.selfPropExample = obj; // circular reference
throw obj;
} catch (error) {
// Statements that execute in the event of an exception
}
</syntaxhighlight>
 
=== ooRexxKotlin ===
{{Further|Kotlin (programming language)}}
<syntaxhighlight lang="rexxkotlin">
try {
// Code that may throw an exception
} catch (e: SomeException) {
// Code for handling the exception
}
</syntaxhighlight>
Line 768 ⟶ 778:
Printexc.record_backtrace true
or by setting the environment variable OCAMLRUNPARAM="b1"*)
</syntaxhighlight>
 
=== ooRexx ===
{{Further|Object REXX}}
<syntaxhighlight lang="rexx">
Signal on Syntax /* switch on SYNTAX trap */
 
Say 1 + "AString" /* an impossible calculation */
 
Exit
 
SYNTAX:
ConditionObject = Condition(Object) /* get additional information */
say "Error code is" ConditionObject~Code /* output: Error code is 41.1 */
say ConditionObject~ErrorText /* output: Bad arithmetic conversion. */
</syntaxhighlight>