Jump to content

ERROR cases


hackalive

Recommended Posts

What do you exactly want to achieve? You can also just use exception's:

 

try {
    $do->something();
} catch (ServerMadeBooBoo $e) {
    echo 'Server made BooBoo.';
    exit(0);
} catch (UserMadeBooBoo $e) {
    echo 'You made BooBoo. You bad BooBoo.';
    exit(0);
}

 

You can also go for the more complex and use a Chain-Of-Responsibility (CoR) pattern:

 

$errorHandler = new ServerMadeBooBoo(new UserMadeBooBoo());

$errorHandler->handle(MY_ERR_CBOOBOO); // Output: You made BooBoo. You bad BooBoo.

 

So what do you exactly want to achieve?

Link to comment
Share on other sites

okay so I have on index.php

 

function errors($errno, $errstr, $errfile, $errline)
{
    switch ($errno) {
case E_TEST_WARNING:
	echo "<b>DEPRECATED</b> [$errno] $errstr [$errfile on $errline]<br />\n";
	break;
}
    return true;
}

set_error_handler("errors");

trigger_error("IC_00_00_test",E_TEST_WARNING);

 

but this is returning

Use of undefined constant E_TEST_WARNING - assumed 'E_TEST_WARNING'

 

any ideas?

 

Link to comment
Share on other sites

I told you: you can NOT use custom error constants with built-in functions. You can only replicate this behavior by using your own defined functions:

 

function my_trigger_error($errstr, $errno = MY_ERR_NOTICE) {
    if (MY_ERR_NOTICE === $errno) {
        echo 'something';
        exit(0);
    }
}

//in your code somewhere:
my_trigger_error('BooBoo');

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.