close
   


#include <exception>

using std::exception;
class DivideByZeroException : public exception {
public:
    
        // 建構子:直接實作,指定錯誤訊息
    DivideByZeroException() : exception("attempted to divide by zero111") {}

}; // end class DivideByZeroException 


//REF:http://www.nhu.edu.tw/~CSIE/ycliaw/OOP/13_Exception.pdf
double quotient(int numerator, int denominator)
 {
    // 假如除數為0丟出 DivideByZeroException 例外並結束此函式
         if (denominator == 0)
         throw DivideByZeroException(); //丟出例外並結束函式執行
   
        // 傳回除法運算結果
        return static_cast<double>(numerator) / denominator;
    
} // end function quotient

image
 
image  

 

arrow
arrow
    全站熱搜

    天才R 發表在 痞客邦 留言(0) 人氣()