KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > caucho > quercus > lib > ExceptionClass


1 /*
2  * Copyright (c) 1998-2006 Caucho Technology -- all rights reserved
3  *
4  * This file is part of Resin(R) Open Source
5  *
6  * Each copy or derived work must preserve the copyright notice and this
7  * notice unmodified.
8  *
9  * Resin Open Source is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * Resin Open Source is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
17  * of NON-INFRINGEMENT. See the GNU General Public License for more
18  * details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with Resin Open Source; if not, write to the
22  *
23  * Free Software Foundation, Inc.
24  * 59 Temple Place, Suite 330
25  * Boston, MA 02111-1307 USA
26  *
27  * @author Charles Reich
28  */

29
30 package com.caucho.quercus.lib;
31
32 import com.caucho.quercus.Location;
33 import com.caucho.quercus.annotation.ClassImplementation;
34 import com.caucho.quercus.annotation.Optional;
35 import com.caucho.quercus.annotation.This;
36 import com.caucho.quercus.env.Env;
37 import com.caucho.quercus.env.LongValue;
38 import com.caucho.quercus.env.ObjectValue;
39 import com.caucho.quercus.env.StringValue;
40 import com.caucho.quercus.env.StringValueImpl;
41 import com.caucho.quercus.env.Value;
42
43 /**
44  * Exception object facade.
45  */

46 @ClassImplementation
47 public class ExceptionClass {
48   /**
49    * Create a new exception API object.
50    */

51   public static Value __construct(Env env,
52                                   @This ObjectValue value,
53                                   @Optional StringValue message,
54                                   @Optional("0") int code)
55   {
56     value.putField(env, "message", message);
57     value.putField(env, "code", LongValue.create(code));
58
59     Location location = env.getLocation();
60     if (location != null) {
61       if (location.getFileName() != null)
62         value.putField(env, "file", new StringValueImpl(location.getFileName()));
63       else
64         value.putField(env, "file", new StringValueImpl("unknown"));
65
66       value.putField(env, "line", new LongValue(location.getLineNumber()));
67     }
68
69     value.putField(env, "trace", ErrorModule.debug_backtrace(env));
70
71     return value;
72   }
73
74   /**
75    * Returns the message.
76    */

77   public static Value getMessage(Env env, @This ObjectValue obj)
78   {
79     return obj.getField(env, "message");
80   }
81
82   /**
83    * Returns the code.
84    */

85   public static Value getCode(Env env, @This ObjectValue obj)
86   {
87     return obj.getField(env, "code");
88   }
89
90   /**
91    * Returns the file.
92    */

93   public static Value getFile(Env env, @This ObjectValue obj)
94   {
95     return obj.getField(env, "file");
96   }
97
98   /**
99    * Returns the line.
100    */

101   public static Value getLine(Env env, @This ObjectValue obj)
102   {
103     return obj.getField(env, "line");
104   }
105
106   /**
107    * Returns the trace.
108    */

109   public static Value getTrace(Env env, @This ObjectValue obj)
110   {
111     return obj.getField(env, "trace");
112   }
113
114   /**
115    * Returns the trace.
116    */

117   public static Value getTraceAsString(Env env, @This ObjectValue obj)
118   {
119     return new StringValueImpl("<trace>");
120   }
121 }
122
Popular Tags