Skip to content

Commit 8aba90d

Browse files
committed
Change exception type
1 parent 3b020f6 commit 8aba90d

File tree

6 files changed

+52
-14
lines changed

6 files changed

+52
-14
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
/**
3+
* PHPWord
4+
*
5+
* Copyright (c) 2014 PHPWord
6+
*
7+
* This library is free software; you can redistribute it and/or
8+
* modify it under the terms of the GNU Lesser General Public
9+
* License as published by the Free Software Foundation; either
10+
* version 2.1 of the License, or (at your option) any later version.
11+
*
12+
* This library is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15+
* Lesser General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU Lesser General Public
18+
* License along with this library; if not, write to the Free Software
19+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20+
*
21+
* @category PHPWord
22+
* @package PHPWord
23+
* @copyright Copyright (c) 2014 PHPWord
24+
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
25+
* @version 0.8.0
26+
*/
27+
namespace PhpOffice\PhpWord\Exceptions;
28+
29+
/**
30+
* Exception used for when an image is not found
31+
*/
32+
class InvalidObjectException extends Exception
33+
{
34+
}

src/PhpWord/Section.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@
2525

2626
namespace PhpOffice\PhpWord;
2727

28-
use PhpOffice\PhpWord\Exceptions\Exception;
28+
use PhpOffice\PhpWord\Exceptions\InvalidImageException;
29+
use PhpOffice\PhpWord\Exceptions\InvalidObjectException;
2930
use PhpOffice\PhpWord\Section\Footer;
3031
use PhpOffice\PhpWord\Section\Image;
3132
use PhpOffice\PhpWord\Section\Header;
@@ -229,7 +230,7 @@ public function addListItem($text, $depth = 0, $styleFont = null, $styleList = n
229230
* @param string $src
230231
* @param mixed $style
231232
* @return \PhpOffice\PhpWord\Section\Object
232-
* @throws \PhpOffice\PhpWord\Exceptions\Exception
233+
* @throws \PhpOffice\PhpWord\Exceptions\InvalidObjectException
233234
*/
234235
public function addObject($src, $style = null)
235236
{
@@ -260,8 +261,9 @@ public function addObject($src, $style = null)
260261

261262
$this->_elementCollection[] = $object;
262263
return $object;
264+
} else {
265+
throw new InvalidObjectException;
263266
}
264-
throw new Exception('Source does not exist or unsupported object type.');
265267
}
266268

267269
/**
@@ -270,7 +272,7 @@ public function addObject($src, $style = null)
270272
* @param string $src
271273
* @param mixed $style
272274
* @return \PhpOffice\PhpWord\Section\Image
273-
* @throws \PhpOffice\PhpWord\Exceptions\Exception
275+
* @throws \PhpOffice\PhpWord\Exceptions\InvalidImageException
274276
*/
275277
public function addImage($src, $style = null)
276278
{
@@ -281,7 +283,7 @@ public function addImage($src, $style = null)
281283
$this->_elementCollection[] = $image;
282284
return $image;
283285
} else {
284-
throw new Exception('Source does not exist or unsupported image type.');
286+
throw new InvalidImageException;
285287
}
286288
}
287289

src/PhpWord/Section/Footer.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626
namespace PhpOffice\PhpWord\Section;
2727

28-
use PhpOffice\PhpWord\Exceptions\Exception;
28+
use PhpOffice\PhpWord\Exceptions\InvalidImageException;
2929
use PhpOffice\PhpWord\Media;
3030
use PhpOffice\PhpWord\Section\Footer\PreserveText;
3131
use PhpOffice\PhpWord\Shared\String;
@@ -140,7 +140,7 @@ public function addImage($src, $style = null)
140140
$this->_elementCollection[] = $image;
141141
return $image;
142142
} else {
143-
throw new Exception('Source does not exist or unsupported image type.');
143+
throw new InvalidImageException;
144144
}
145145
}
146146

src/PhpWord/Section/Header.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626
namespace PhpOffice\PhpWord\Section;
2727

28-
use PhpOffice\PhpWord\Exceptions\Exception;
28+
use PhpOffice\PhpWord\Exceptions\InvalidImageException;
2929
use PhpOffice\PhpWord\Media;
3030
use PhpOffice\PhpWord\Section\Footer\PreserveText;
3131
use PhpOffice\PhpWord\Shared\String;
@@ -169,7 +169,7 @@ public function addImage($src, $style = null)
169169
$this->_elementCollection[] = $image;
170170
return $image;
171171
} else {
172-
throw new Exception('Source does not exist or unsupported image type.');
172+
throw new InvalidImageException;
173173
}
174174
}
175175

@@ -219,7 +219,7 @@ public function addWatermark($src, $style = null)
219219
$this->_elementCollection[] = $image;
220220
return $image;
221221
} else {
222-
throw new Exception('Src does not exist or invalid image type.');
222+
throw new InvalidImageException;
223223
}
224224
}
225225

src/PhpWord/Section/Table/Cell.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
namespace PhpOffice\PhpWord\Section\Table;
2727

2828
use PhpOffice\PhpWord\Exceptions\Exception;
29+
use PhpOffice\PhpWord\Exceptions\InvalidObjectException;
30+
use PhpOffice\PhpWord\Exceptions\InvalidImageException;
2931
use PhpOffice\PhpWord\Media;
3032
use PhpOffice\PhpWord\Section\Footer\PreserveText;
3133
use PhpOffice\PhpWord\Section\Image;
@@ -212,7 +214,7 @@ public function addImage($src, $style = null)
212214
$this->_elementCollection[] = $image;
213215
return $image;
214216
} else {
215-
throw new Exception('Source does not exist or unsupported image type.');
217+
throw new InvalidImageException;
216218
}
217219
}
218220

@@ -265,7 +267,7 @@ public function addObject($src, $style = null)
265267
$this->_elementCollection[] = $object;
266268
return $object;
267269
} else {
268-
throw new Exception('Source does not exist or unsupported object type.');
270+
throw new InvalidObjectException;
269271
}
270272
}
271273

src/PhpWord/Section/TextRun.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626
namespace PhpOffice\PhpWord\Section;
2727

28-
use PhpOffice\PhpWord\Exceptions\Exception;
28+
use PhpOffice\PhpWord\Exceptions\InvalidImageException;
2929
use PhpOffice\PhpWord\Media;
3030
use PhpOffice\PhpWord\Shared\String;
3131
use PhpOffice\PhpWord\Style\Paragraph;
@@ -131,7 +131,7 @@ public function addImage($imageSrc, $style = null)
131131
$this->_elementCollection[] = $image;
132132
return $image;
133133
} else {
134-
throw new Exception('Source does not exist or unsupported image type.');
134+
throw new InvalidImageException;
135135
}
136136
}
137137

0 commit comments

Comments
 (0)