1. 예외명세란?
- 함수가 내보낼 수 있는 예외목록을 나열한 것입니다.
2. 형식
- int aaa() throw (int , char)
- 위와같이 해당되는 타입을 작성하면 그에 해당하는 예외만 발생시킵니다.
- 만약 함수내 throw가 위와 같은 형식의 예외를 발생시키지 않는다면 unexpected함수를 불러냅니다.
3. throw()?
- 만약 함수 뒤에 throw()라고 선언되어 있으면 예외를 내보내지 않습니다.
- 마찬가지로 throw()라고 명세되어 있는 함수에서 예외를 발생 시킬려고 하면 unexpected함수를 불러냅니다.
4. exception헤더에 정의된 예상하지 않는 예외처리에 괸련된 함수 목록
/// Takes a new handler function as an argument, returns the old function.
unexpected_handler set_unexpected(unexpected_handler) throw();
// If you write a replacement %unexpected handler, it must be of this type.
// 함수포인터 선언
typedef void (*unexpected_handler) ();
/** The runtime will call this function if an %exception is thrown which
* violates the function's %exception specification. */
void unexpected() __attribute__ ((__noreturn__));
- unexpected함수는 set_unexpected에 등록된 함수를 호출합니다. set_unexpected함수를 보면 함수포인터를 입력받아 해당 타입을 리턴하는 형태를 지니고 있습니다. 그리고 실제 위의 함수들은 예외처리함수이므로 예외자체를 허용하지 않는 형태로 정의되어 있습니다.