Programmer's Reference Guide

Zend_Exception

例外の使用法

Zend_Exception は、 Zend Framework のクラスがスローするすべての例外の基底クラスとなります。

例1 例外のキャッチ

次のコードは、Zend Framework のクラスからスローされた例外をキャッチする方法を示すものです。

  1. try {
  2.     // Zend_Loader::loadClass() で、存在しないクラスを指定してコールすると
  3.     // Zend_Loader で例外がスローされます
  4.     Zend_Loader::loadClass('nonexistantclass');
  5. } catch (Zend_Exception $e) {
  6.     echo "キャッチした例外: " . get_class($e) . "\n";
  7.     echo "メッセージ: " . $e->getMessage() . "\n";
  8.     // その他、エラーから復帰するためのコード
  9. }

Zend_Exception を使用すると、 Zend Framework のクラスがスローするすべての例外を catch ブロックで捕捉できるようになります。 個々の例外をすべて個別に捕捉できないような場合に便利です。

Zend Framework の各コンポーネントのドキュメントには、 どのメソッドでどんな場合に例外をスローするのかや、 どのような例外クラスがスローされるのかが記載されています。


Zend_Exception

Comments

Good afternoon.

My question is about using exception an zend framework, how to handle database exceptions and as I can manage them correctly and send a message to the view.

thanks for your time.
Good afternoon.

My question is about using exception an zend framework, how to handle database exceptions and as I can manage them correctly and send a message to the view.

thanks for your time.

+ Add A Comment

Please do not report issues via comments; use the ZF Issue Tracker.

If you have a JIRA/Crowd account, we suggest you login first before commenting.

  • BBCode is allowed in the comment markup

  • Select a Version

    Languages Available

    Components

    Search the Manual