root/trunk/classes/phing/BuildException.php

Revision 307, 3.4 kB (checked in by hans, 1 year ago)

Refs #188 - Adding work-in-progress (still-broken!) namespace support.

  • Property svn:keywords set to author date id revision
Line 
1 <?php
2 /*
3  *  $Id$
4  *
5  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
6  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
7  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
8  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
9  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
10  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
11  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
12  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
13  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
14  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
15  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
16  *
17  * This software consists of voluntary contributions made by many individuals
18  * and is licensed under the LGPL. For more information please see
19  * <http://phing.info>.
20  */
21
22 namespace phing;
23 use phing::parser::Location;
24
25 /**
26  * BuildException is for when things go wrong in a build execution.
27  *
28  * @author   Andreas Aderhold <andi@binarycloud.com>
29  * @version  $Revision: 1.12 $
30  * @package  phing
31  */
32 class BuildException extends Exception {
33
34     /**
35      * Location in the xml file.
36      * @var Location
37      */
38     protected $location;
39             
40     /**
41      * The nested "cause" exception.
42      * @var Exception
43      */
44     protected $cause;
45     
46     /**
47      * Construct a BuildException.
48      * Supported signatures:
49      *         throw new BuildException($causeExc);
50      *         throw new BuildException($msg);
51      *         throw new Buildexception($causeExc, $loc);
52      *         throw new BuildException($msg, $causeExc);
53      *         throw new BuildException($msg, $loc);
54      *         throw new BuildException($msg, $causeExc, $loc);
55      */
56     function __construct($p1, $p2 = null, $p3 = null) {       
57         
58         $cause = null;
59         $loc = null;
60         $msg = "";
61         
62         if ($p3 !== null) {
63             $cause = $p2;
64             $loc = $p3;
65             $msg = $p1;
66         } elseif ($p2 !== null) {
67             if ($p2 instanceof Exception) {
68                 $cause = $p2;
69                 $msg = $p1;
70             } elseif ($p2 instanceof Location) {
71                 $loc = $p2;
72                 if ($p1 instanceof Exception) {
73                     $cause = $p1;
74                 } else {
75                     $msg = $p1;
76                 }
77             }
78         } elseif ($p1 instanceof Exception) {
79             $cause = $p1;
80         } else {
81             $msg = $p1;
82         }
83         
84         parent::__construct($msg);
85         
86         if ($cause !== null) {
87             $this->cause = $cause;
88             $this->message .= " [wrapped: " . $cause->getMessage() ."]";
89         }
90         
91         if ($loc !== null) {
92             $this->setLocation($loc);
93         }               
94     }
95     
96     /**
97      * Gets the cause exception.
98      *
99      * @return Exception
100      */
101     public function getCause() {
102         return $this->cause;
103     }
104     
105     /**
106      * Gets the location of error in XML file.
107      *
108      * @return Location
109      */
110     public function getLocation() {
111         return $this->location;
112     }
113
114     /**
115      * Sets the location of error in XML file.
116      *
117      * @param Locaiton $loc
118      */
119     public function setLocation(Location $loc) {       
120         $this->location = $loc;
121         $this->message = $loc->toString() . ': ' . $this->message;
122     }
123
124 }
125
Note: See TracBrowser for help on using the browser.