水曜日, 8月 31, 2011

Java and C++ Exception Handling

Java and C++ differs in how to handle exceptions. In Java, every possible exception must be handled. In C++, the exceptions handling can be omitted.

The demerit of not having to write exception handling procedure is not of optimization but in the safe programming practice. The exceptions readied for the methods will be thrown away, which might cause some fatal errors. Java has it that those have to be taken care of. Every method that throws exceptions must declare as "throws Exception" or any exception class. When the method is called, it must be in the try-catch block.

The counter argument is that when exception handling can be omitted, the code can be short as pointed out by this g++ user(s), the program size will not be affected unless the exceptions are explicitly stated to be thrown and handled in case of the g++ compiler. You can safely ignore any error message the original library writer tried to warn you in calling the methods. And those who use the method won't be warned as well.

There is no way to assume that any method won't throw exceptions, unless explicitly stated as in Java code, as throws Exception. Going through all the possibilities to make sure that the method that you are calling does not call just any method that throws exceptions, is if not an impossible task then tedious work. Therefore, this practice may leave the programmer unsafe and the products made from those libraries.

I2S プロトコル

I²S(Inter-IC Sound)は、マイコンやオーディオ機器間で音声データをやり取りするために設計された、シリアル通信プロトコルです。I²CやSPIと名前は似ていますが、I²Sは音声専用のプロトコルです。 I²Sは、以下の3つの主要な信号線を使って通信します。 BCLK (...