Skip to content

Commit 7c3ed6f

Browse files
committed
Fix exception types
1 parent 0cbe010 commit 7c3ed6f

5 files changed

+13
-16
lines changed

ext/date/php_date.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4131,7 +4131,7 @@ PHP_METHOD(DatePeriod, __construct)
41314131
dpobj->current = NULL;
41324132

41334133
if (isostr) {
4134-
zend_replace_error_handling(EH_THROW, NULL, &error_handling);
4134+
zend_replace_error_handling(EH_THROW, zend_ce_value_error, &error_handling);
41354135
date_period_initialize(&(dpobj->start), &(dpobj->end), &(dpobj->interval), &recurrences, isostr, isostr_len);
41364136
zend_restore_error_handling(&error_handling);
41374137
if (EG(exception)) {
@@ -4140,19 +4140,19 @@ PHP_METHOD(DatePeriod, __construct)
41404140

41414141
if (dpobj->start == NULL) {
41424142
zend_string *func = get_active_function_or_method_name();
4143-
zend_throw_error(NULL, "%s(): Argument #1 must contain a start date, \"%s\" given", ZSTR_VAL(func), isostr);
4143+
zend_value_error("%s(): Argument #1 must contain a start date, \"%s\" given", ZSTR_VAL(func), isostr);
41444144
zend_string_release(func);
41454145
RETURN_THROWS();
41464146
}
41474147
if (dpobj->interval == NULL) {
41484148
zend_string *func = get_active_function_or_method_name();
4149-
zend_throw_error(NULL, "%s(): Argument #1 must contain an interval, \"%s\" given", ZSTR_VAL(func), isostr);
4149+
zend_value_error("%s(): Argument #1 must contain an interval, \"%s\" given", ZSTR_VAL(func), isostr);
41504150
zend_string_release(func);
41514151
RETURN_THROWS();
41524152
}
41534153
if (dpobj->end == NULL && recurrences == 0) {
41544154
zend_string *func = get_active_function_or_method_name();
4155-
zend_throw_error(NULL, "%s(): Argument #1 must contain an end date or a recurrence count, \"%s\" given", ZSTR_VAL(func), isostr);
4155+
zend_value_error("%s(): Argument #1 must contain an end date or a recurrence count, \"%s\" given", ZSTR_VAL(func), isostr);
41564156
zend_string_release(func);
41574157
RETURN_THROWS();
41584158
}
@@ -4194,7 +4194,7 @@ PHP_METHOD(DatePeriod, __construct)
41944194

41954195
if (dpobj->end == NULL && recurrences < 1) {
41964196
zend_string *func = get_active_function_or_method_name();
4197-
zend_throw_error(NULL, "%s(): Recurrence count must be greater than 0", ZSTR_VAL(func));
4197+
zend_value_error("%s(): Recurrence count must be greater than 0", ZSTR_VAL(func));
41984198
zend_string_release(func);
41994199
RETURN_THROWS();
42004200
}

ext/date/tests/DatePeriod_wrong_recurrence_on_constructor.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ DatePeriod: Test wrong recurrence parameter on __construct
44
<?php
55
try {
66
new DatePeriod(new DateTime('yesterday'), new DateInterval('P1D'), 0);
7-
} catch (Exception $exception) {
7+
} catch (ValueError $exception) {
88
echo $exception->getMessage(), "\n";
99
}
1010

1111
try {
1212
new DatePeriod(new DateTime('yesterday'), new DateInterval('P1D'), -1);
13-
} catch (Exception $exception) {
13+
} catch (ValueError $exception) {
1414
echo $exception->getMessage(), "\n";
1515
}
1616

ext/date/tests/bug44562.phpt

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,9 @@ Bug #44562 (Creating instance of DatePeriod crashes)
44
<?php
55
date_default_timezone_set('Europe/Oslo');
66

7-
try
8-
{
7+
try {
98
$dp = new DatePeriod('2D');
10-
}
11-
catch ( Exception $e )
12-
{
9+
} catch (ValueError $e) {
1310
echo $e->getMessage(), "\n";
1411
}
1512

ext/date/tests/bug54283.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Bug #54283 (new DatePeriod(NULL) causes crash)
55

66
try {
77
var_dump(new DatePeriod(NULL));
8-
} catch (Exception $e) {
8+
} catch (ValueError $e) {
99
var_dump($e->getMessage());
1010
}
1111

ext/date/tests/date_interval_bad_format_leak.phpt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,19 @@ DateInterval with bad format should not leak period
55

66
try {
77
$interval = new DateInterval('P3"D');
8-
} catch (Exception $e) {
8+
} catch (ValueError $e) {
99
echo $e->getMessage(), "\n";
1010
}
1111

1212
try {
1313
$perid = new DatePeriod('P3"D');
14-
} catch (Exception $e) {
14+
} catch (ValueError $e) {
1515
echo $e->getMessage(), "\n";
1616
}
1717

1818
try {
1919
new DatePeriod('2008-03-01T12:00:00Z1');
20-
} catch (Exception $e) {
20+
} catch (ValueError $e) {
2121
echo $e->getMessage(), "\n";
2222
}
2323

0 commit comments

Comments
 (0)