Exceptions: Difference between revisions
Content added Content deleted
m (→{{header|Wren}}: Changed to Wren S/H) |
m (→{{header|Sidef}}: updated code) |
||
Line 3,094: | Line 3,094: | ||
An exception is thrown by the ''die'' keyword, which, if not caught, it terminates the program with an appropriate exit code. |
An exception is thrown by the ''die'' keyword, which, if not caught, it terminates the program with an appropriate exit code. |
||
<syntaxhighlight lang="ruby">try { |
<syntaxhighlight lang="ruby">try { |
||
die "I'm dead!" |
die "I'm dead!" # throws an exception |
||
⚫ | |||
⚫ | |||
⚫ | |||
} |
} |
||
⚫ | |||
say "type: #{type}"; # type: error |
|||
⚫ | |||
⚫ | |||
say "I'm alive..." |
say "I'm alive..." |
||
die "Now I'm dead!" |
die "Now I'm dead!" # this line terminates the program |
||
say "Or am I?" |
say "Or am I?" # Yes, you are!</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 3,109: | Line 3,108: | ||
msg: I'm dead! at test.sf line 2. |
msg: I'm dead! at test.sf line 2. |
||
I'm alive... |
I'm alive... |
||
Now I'm dead! at test.sf line |
Now I'm dead! at test.sf line 9. |
||
</pre> |
</pre> |
||