0

I want to create a class in my framework for exception handling.
How can write the class to be able doing exception handling without using try catch in my codes?
Here is a example:

I tried but couldn't write the code here

exception.php  

class Soroush_Exception extends   
    //some code here      
} 

===============================  
file1.php  

$a = 2;  
if ($a != 3)  
{  
    throw new Soroush_Exception("Error");   
}  
//and here I want to show it without using catch with a static method  
echo Soroush_Exception::show();

sorry for bad english

3
  • Your link doesn't work (500 error). And maybe explain why you want this. It sounds like a bad idea :( Commented Jan 8, 2012 at 10:22
  • Your post may have been blocked because you did not apply code formatting, see here for how it's done. Commented Jan 8, 2012 at 10:24
  • Why would you want to emulate exception handling without try/catch? That's essentially the whole point of exceptions! Commented Jan 8, 2012 at 10:27

2 Answers 2

1

Use trigger_error function: php.net/trigger_error

Sign up to request clarification or add additional context in comments.

Comments

0

Set a class' method as exception handler - it will catch any exception, that was not catched explicitly with a catch statement.

The problem is that exception stops execution of the script to the point where it is catched, and continue from the catch afterwards. If there is no catch, you still can execute code in the exception handler, but after the handler method the script will stop.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.