1 module javascriptcore.Exception;
2 
3 private import glib.ConstructionException;
4 private import glib.Str;
5 private import gobject.ObjectG;
6 private import javascriptcore.Context;
7 private import javascriptcore.c.functions;
8 public  import javascriptcore.c.types;
9 
10 
11 /**
12  * JSCException represents a JavaScript exception.
13  */
14 public class JException : ObjectG
15 {
16 	/** the main Gtk struct */
17 	protected JSCException* jSCException;
18 
19 	/** Get the main Gtk struct */
20 	public JSCException* getExceptionStruct(bool transferOwnership = false)
21 	{
22 		if (transferOwnership)
23 			ownedRef = false;
24 		return jSCException;
25 	}
26 
27 	/** the main Gtk struct as a void* */
28 	protected override void* getStruct()
29 	{
30 		return cast(void*)jSCException;
31 	}
32 
33 	/**
34 	 * Sets our main struct and passes it to the parent class.
35 	 */
36 	public this (JSCException* jSCException, bool ownedRef = false)
37 	{
38 		this.jSCException = jSCException;
39 		super(cast(GObject*)jSCException, ownedRef);
40 	}
41 
42 
43 	/** */
44 	public static GType getType()
45 	{
46 		return jsc_exception_get_type();
47 	}
48 
49 	/**
50 	 * Create a new #JSCException in @context with @message.
51 	 *
52 	 * Params:
53 	 *     context = a #JSCContext
54 	 *     message = the error message
55 	 *
56 	 * Returns: a new #JSCException.
57 	 *
58 	 * Throws: ConstructionException GTK+ fails to create the object.
59 	 */
60 	public this(Context context, string message)
61 	{
62 		auto __p = jsc_exception_new((context is null) ? null : context.getContextStruct(), Str.toStringz(message));
63 
64 		if(__p is null)
65 		{
66 			throw new ConstructionException("null returned by new");
67 		}
68 
69 		this(cast(JSCException*) __p, true);
70 	}
71 
72 	/**
73 	 * Create a new #JSCException in @context using a formatted string
74 	 * for the message. This is similar to jsc_exception_new_printf()
75 	 * except that the arguments to the format string are passed as a va_list.
76 	 *
77 	 * Params:
78 	 *     context = a #JSCContext
79 	 *     format = the string format
80 	 *     args = the parameters to insert into the format string
81 	 *
82 	 * Returns: a new #JSCException.
83 	 *
84 	 * Throws: ConstructionException GTK+ fails to create the object.
85 	 */
86 	public this(Context context, string format, void* args)
87 	{
88 		auto __p = jsc_exception_new_vprintf((context is null) ? null : context.getContextStruct(), Str.toStringz(format), args);
89 
90 		if(__p is null)
91 		{
92 			throw new ConstructionException("null returned by new_vprintf");
93 		}
94 
95 		this(cast(JSCException*) __p, true);
96 	}
97 
98 	/**
99 	 * Create a new #JSCException in @context with @name and @message.
100 	 *
101 	 * Params:
102 	 *     context = a #JSCContext
103 	 *     name = the error name
104 	 *     message = the error message
105 	 *
106 	 * Returns: a new #JSCException.
107 	 *
108 	 * Throws: ConstructionException GTK+ fails to create the object.
109 	 */
110 	public this(Context context, string name, string message)
111 	{
112 		auto __p = jsc_exception_new_with_name((context is null) ? null : context.getContextStruct(), Str.toStringz(name), Str.toStringz(message));
113 
114 		if(__p is null)
115 		{
116 			throw new ConstructionException("null returned by new_with_name");
117 		}
118 
119 		this(cast(JSCException*) __p, true);
120 	}
121 
122 	/**
123 	 * Create a new #JSCException in @context with @name and using a formatted string
124 	 * for the message. This is similar to jsc_exception_new_with_name_printf()
125 	 * except that the arguments to the format string are passed as a va_list.
126 	 *
127 	 * Params:
128 	 *     context = a #JSCContext
129 	 *     name = the error name
130 	 *     format = the string format
131 	 *     args = the parameters to insert into the format string
132 	 *
133 	 * Returns: a new #JSCException.
134 	 *
135 	 * Throws: ConstructionException GTK+ fails to create the object.
136 	 */
137 	public this(Context context, string name, string format, void* args)
138 	{
139 		auto __p = jsc_exception_new_with_name_vprintf((context is null) ? null : context.getContextStruct(), Str.toStringz(name), Str.toStringz(format), args);
140 
141 		if(__p is null)
142 		{
143 			throw new ConstructionException("null returned by new_with_name_vprintf");
144 		}
145 
146 		this(cast(JSCException*) __p, true);
147 	}
148 
149 	/**
150 	 * Get a string with the exception backtrace.
151 	 *
152 	 * Returns: the exception backtrace string or %NULL.
153 	 */
154 	public string getBacktraceString()
155 	{
156 		return Str.toString(jsc_exception_get_backtrace_string(jSCException));
157 	}
158 
159 	/**
160 	 * Get the column number at which @exception happened.
161 	 *
162 	 * Returns: the column number of @exception.
163 	 */
164 	public uint getColumnNumber()
165 	{
166 		return jsc_exception_get_column_number(jSCException);
167 	}
168 
169 	/**
170 	 * Get the line number at which @exception happened.
171 	 *
172 	 * Returns: the line number of @exception.
173 	 */
174 	public uint getLineNumber()
175 	{
176 		return jsc_exception_get_line_number(jSCException);
177 	}
178 
179 	/**
180 	 * Get the error message of @exception.
181 	 *
182 	 * Returns: the @exception error message.
183 	 */
184 	public string getMessage()
185 	{
186 		return Str.toString(jsc_exception_get_message(jSCException));
187 	}
188 
189 	/**
190 	 * Get the error name of @exception
191 	 *
192 	 * Returns: the @exception error name.
193 	 */
194 	public string getName()
195 	{
196 		return Str.toString(jsc_exception_get_name(jSCException));
197 	}
198 
199 	/**
200 	 * Get the source URI of @exception.
201 	 *
202 	 * Returns: the the source URI of @exception, or %NULL.
203 	 */
204 	public string getSourceUri()
205 	{
206 		return Str.toString(jsc_exception_get_source_uri(jSCException));
207 	}
208 
209 	/**
210 	 * Return a report message of @exception, containing all the possible details such us
211 	 * source URI, line, column and backtrace, and formatted to be printed.
212 	 *
213 	 * Returns: a new string with the exception report
214 	 */
215 	public string report()
216 	{
217 		auto retStr = jsc_exception_report(jSCException);
218 
219 		scope(exit) Str.freeString(retStr);
220 		return Str.toString(retStr);
221 	}
222 
223 	/**
224 	 * Get the string representation of @exception error.
225 	 *
226 	 * Returns: the string representation of @exception.
227 	 */
228 	public override string toString()
229 	{
230 		auto retStr = jsc_exception_to_string(jSCException);
231 
232 		scope(exit) Str.freeString(retStr);
233 		return Str.toString(retStr);
234 	}
235 }