异常(Throwing Exceptions)¶

When you throw an exception using the Phalcon API, the current flow of execution will be stopped, returningto the last PHP code block when a Phalcon method where called.

There are two ways to throw exceptions, the first, when the exception object only receives a string as parameter:

  1. PHALCON_THROW_EXCEPTION_STR(phalcon_exception_ce, "Hey this is an exception");

Or building the exception manually and then throwing it:

  1. PHALCON_CONCAT_SVS(&exception_message, "Unable to insert into ", table, " without data");
  2.  
  3. object_init_ex(&exception, phalcon_db_exception_ce);
  4.  
  5. // The exception constructor must be manually called
  6. PHALCON_CALL_METHOD(NULL, &exception, "__construct", &exception_message);
  7. phalcon_throw_exception(&exception);
  8. return;

原文: http://www.myleftstudio.com/internals/exceptions.html