Questions tagged «drupal-6»

5
在PHP Try Catch块中引发异常
我在Drupal 6 .module文件中有一个PHP函数。我试图在执行更复杂的任务(例如数据库查询)之前运行初始变量验证。在C#中,我曾经在Try块的开头实现IF语句,如果验证失败,该语句将引发新的异常。抛出的异常将在Catch块中捕获。以下是我的PHP代码: function _modulename_getData($field, $table) { try { if (empty($field)) { throw new Exception("The field is undefined."); } // rest of code here... } catch (Exception $e) { throw $e->getMessage(); } } 但是,当我尝试运行代码时,它告诉我只能在Catch块内抛出对象。 提前致谢!
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.