<!-- ##### SECTION Title ##### -->
Exception Handling

<!-- ##### SECTION Short_Description ##### -->
Throwing and catching exceptions

<!-- ##### SECTION Long_Description ##### -->
<para>
Seed uses exceptions as a method of handling runtime errors within scripts. An exception consists of a name (a list of commonly-used exception names is below), a message, detailing the error, and the line number and filename from which the exception was raised. If Seed cannot determine from where the exception was raised, the line number and filename will be undefined. seed_exception_to_string() provides a simple way to convert all of these into a consistent representation to display to users.
</para>

<para>
All Seed callbacks take an exception argument; calling
seed_make_exception() with this argument and the details you wish to
fill it with will propogate that exception up the chain. Exceptions
can be <emphasis>caught</emphasis> either by a try/catch block in the
calling JavaScript, or by observing the exception property, dealing
with it, and then clearing the exception.

It is important to note that calling seed_make_exception() does not
in fact <emphasis>throw</emphasis> the exception, but just creates an
object which, when stored in the exception pointer passed to a callback,
causes JSC to throw an exception once flow is returned.
</para>

<example>
<title>Throw an exception, because <function>random_callback</function> was called with the wrong number of arguments</title>
<programlisting>
SeedValue random_callback(SeedContext ctx,
                          SeedObject function,
                          SeedObject this_object,
                          gsize argument_count,
                          const SeedValue arguments[],
                          SeedException *exception)
{
    ...
&nbsp;
    if(argument_count != 1)
    {
        seed_make_exception(ctx, exception, "ArgumentError",
                            "wrong number of arguments; expected 1, got %zd",
                            argument_count);
        return seed_make_undefined(ctx);
    }
&nbsp;
    ...
}
</programlisting>
</example>

<note>
<title>Predefined Exception Names</title>
<para>
<itemizedlist>
  <listitem><emphasis>InvalidPropertyValue</emphasis> - a property was set to a value out of range</listitem>
  <listitem><emphasis>PropertyError</emphasis> - a warning occurred in GLib while trying to set a property</listitem>
  <listitem><emphasis>ArgumentError</emphasis> - a function was called with the wrong number of arguments</listitem>
  <listitem><emphasis>ConversionError</emphasis> - one of the type conversion functions threw an exception</listitem>
  <listitem><emphasis>TypeError</emphasis> - a required argument was of the wrong type</listitem>
  <listitem><emphasis>SyntaxError</emphasis> - a syntax error was thrown from JavaScriptCore</listitem>
  <listitem><emphasis>ParseError</emphasis> - a parsing error was thrown from JavaScriptCore (make sure you close all of your brackets!)</listitem>
  <listitem><emphasis>ReferenceError</emphasis> - a reference error was thrown from JavaScriptCore (most likely, you tried to access a variable which was undefined)</listitem>
</itemizedlist>
</para>
</note>

<!-- ##### SECTION See_Also ##### -->
<para>

</para>

<!-- ##### SECTION Stability_Level ##### -->


<!-- ##### SECTION Image ##### -->


<!-- ##### TYPEDEF SeedException ##### -->
<para>

</para>


<!-- ##### FUNCTION seed_make_exception ##### -->
<para>

</para>

@ctx: 
@exception: 
@name: 
@message: 
@...: 


<!-- ##### FUNCTION seed_exception_get_name ##### -->
<para>

</para>

@ctx: 
@exception: 
@Returns: 


<!-- ##### FUNCTION seed_exception_get_message ##### -->
<para>

</para>

@ctx: 
@exception: 
@Returns: 


<!-- ##### FUNCTION seed_exception_get_line ##### -->
<para>

</para>

@ctx: 
@exception: 
@Returns: 


<!-- ##### FUNCTION seed_exception_get_file ##### -->
<para>

</para>

@ctx: 
@exception: 
@Returns: 


<!-- ##### FUNCTION seed_exception_to_string ##### -->
<para>

</para>

@ctx: 
@exception: 
@Returns: 


