Exception_test.cc revision cd139dc7
1cd139dc7SShuo Chen#include "../Exception.h" 2cd139dc7SShuo Chen#include <stdio.h> 3cd139dc7SShuo Chen 4cd139dc7SShuo Chenclass Bar 5cd139dc7SShuo Chen{ 6cd139dc7SShuo Chen public: 7cd139dc7SShuo Chen void test() 8cd139dc7SShuo Chen { 9cd139dc7SShuo Chen throw muduo::Exception("oops"); 10cd139dc7SShuo Chen } 11cd139dc7SShuo Chen}; 12cd139dc7SShuo Chen 13cd139dc7SShuo Chenvoid foo() 14cd139dc7SShuo Chen{ 15cd139dc7SShuo Chen Bar b; 16cd139dc7SShuo Chen b.test(); 17cd139dc7SShuo Chen} 18cd139dc7SShuo Chen 19cd139dc7SShuo Chenint main() 20cd139dc7SShuo Chen{ 21cd139dc7SShuo Chen try 22cd139dc7SShuo Chen { 23cd139dc7SShuo Chen foo(); 24cd139dc7SShuo Chen } 25cd139dc7SShuo Chen catch (const muduo::Exception& ex) 26cd139dc7SShuo Chen { 27cd139dc7SShuo Chen printf("reason: %s\n", ex.what()); 28cd139dc7SShuo Chen printf("stack trace: %s\n", ex.stackTrace()); 29cd139dc7SShuo Chen } 30cd139dc7SShuo Chen} 31