Skip to content

Commit bc61997

Browse files
committed
add ValueError
ValueError is intended to be thrown when a function or method receives an argument that has the right type (incorrect type should throw a TypeError) but an inappropriate value.
1 parent 628fd6e commit bc61997

File tree

4 files changed

+19
-0
lines changed

4 files changed

+19
-0
lines changed

Zend/zend.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1560,6 +1560,18 @@ ZEND_API ZEND_COLD void zend_argument_count_error(const char *format, ...) /* {{
15601560
va_end(va);
15611561
} /* }}} */
15621562

1563+
ZEND_API ZEND_COLD void zend_value_error(const char *format, ...) /* {{{ */
1564+
{
1565+
va_list va;
1566+
char *message = NULL;
1567+
1568+
va_start(va, format);
1569+
zend_vspprintf(&message, 0, format, va);
1570+
zend_throw_exception(zend_ce_value_error, message, 0);
1571+
efree(message);
1572+
va_end(va);
1573+
} /* }}} */
1574+
15631575
ZEND_API ZEND_COLD void zend_output_debug_string(zend_bool trigger_break, const char *format, ...) /* {{{ */
15641576
{
15651577
#if ZEND_DEBUG

Zend/zend.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,7 @@ ZEND_API ZEND_COLD ZEND_NORETURN void zend_error_at_noreturn(int type, const cha
301301
ZEND_API ZEND_COLD void zend_throw_error(zend_class_entry *exception_ce, const char *format, ...) ZEND_ATTRIBUTE_FORMAT(printf, 2, 3);
302302
ZEND_API ZEND_COLD void zend_type_error(const char *format, ...) ZEND_ATTRIBUTE_FORMAT(printf, 1, 2);
303303
ZEND_API ZEND_COLD void zend_argument_count_error(const char *format, ...) ZEND_ATTRIBUTE_FORMAT(printf, 1, 2);
304+
ZEND_API ZEND_COLD void zend_value_error(const char *format, ...) ZEND_ATTRIBUTE_FORMAT(printf, 1, 2);
304305

305306
ZEND_COLD void zenderror(const char *error);
306307

Zend/zend_exceptions.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ ZEND_API zend_class_entry *zend_ce_compile_error;
3636
ZEND_API zend_class_entry *zend_ce_parse_error;
3737
ZEND_API zend_class_entry *zend_ce_type_error;
3838
ZEND_API zend_class_entry *zend_ce_argument_count_error;
39+
ZEND_API zend_class_entry *zend_ce_value_error;
3940
ZEND_API zend_class_entry *zend_ce_arithmetic_error;
4041
ZEND_API zend_class_entry *zend_ce_division_by_zero_error;
4142

@@ -872,6 +873,10 @@ void zend_register_default_exception(void) /* {{{ */
872873
zend_ce_argument_count_error = zend_register_internal_class_ex(&ce, zend_ce_type_error);
873874
zend_ce_argument_count_error->create_object = zend_default_exception_new;
874875

876+
INIT_CLASS_ENTRY(ce, "ValueError", NULL);
877+
zend_ce_value_error = zend_register_internal_class_ex(&ce, zend_ce_error);
878+
zend_ce_value_error->create_object = zend_default_exception_new;
879+
875880
INIT_CLASS_ENTRY(ce, "ArithmeticError", NULL);
876881
zend_ce_arithmetic_error = zend_register_internal_class_ex(&ce, zend_ce_error);
877882
zend_ce_arithmetic_error->create_object = zend_default_exception_new;

Zend/zend_exceptions.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ extern ZEND_API zend_class_entry *zend_ce_compile_error;
3232
extern ZEND_API zend_class_entry *zend_ce_parse_error;
3333
extern ZEND_API zend_class_entry *zend_ce_type_error;
3434
extern ZEND_API zend_class_entry *zend_ce_argument_count_error;
35+
extern ZEND_API zend_class_entry *zend_ce_value_error;
3536
extern ZEND_API zend_class_entry *zend_ce_arithmetic_error;
3637
extern ZEND_API zend_class_entry *zend_ce_division_by_zero_error;
3738

0 commit comments

Comments
 (0)