override 하는경우의 throw (error handling)
글쓴이: manim / 작성시간: 목, 2006/03/16 - 3:53오후
class B {
public:
virtual void Saturday() throw(Exam);
};
class D : public B {
public:
virtual void Saturday() throw();
};
이 경우의 class D에서의 throw()는 가능하다고 알고 있습니다.
class B {
public:
virtual void Saturday() throw(Exam);
};
class D : public B {
public:
virtual void Saturday() throw(Exam, Party);
};
그런데 이 경우에서는 D에서 throw가 문제가 되는데요
왜, subclass에서의 throw는 argument를 base class보다 같거나 적게 가져야 하는건가요?
Forums:
C++ 문법상 throw 를
C++ 문법상 throw 를 명시할 수 있지만 실제 구현된 컴파일러가 없는 것으로 알고 있었는데...
현재 구현된 컴파일러가 있나요?
그리고 저렇게 명시하는 문법의 장점이 무엇인가요?
에구.. 답이 아니라 질문이라 죄송합니다.
음..
standard exception에 대한 설명에 이런게 나오네요..
- Each class has a what() method that gives a human-readable description of the error.
- All constructors(except exception()) take the human-readable string as an argument.
- Hierarchy allows polymorphic catching of exceptions.
- You can subclass the built-in exceptions to provide more specific exception types.
현재 구현된 컴파일러는.. 잘 모르겠네요 ^^:;
Exception-specifications
Compile Error가 나는 게 맞습니다.
> 왜, subclass에서의 throw는 argument를 base class보다 같거나 적게 가져야 하는건가요?
추상화겠지요.
Base Class만 알고 있는 녀석들이 있을 텐데,
Derived Class에서 다른 걸 던지면 위험하지요.
예외를 못 잡으면 프로세스가 죽을 테고
만약 우주선이라든가 열차라든가 사람 목숨이 걸린 시스템에서
못 잡은 예외는 끔찍한 사고로도 이어집니다.
실제로 유럽 아리안 몇혼가가 익셉션 때문에 공중폭발했읍니다.
GCC/VC 둘 다 지원 안합니다.
[C++98 p296]
15.4 Exception specifications
3 항
If a virtual function has an exception-specification, all declarations, including the definition, of any function that overrides that virtual function in an derived class shall only allow exceptions that are allowed by the exception-specification of the base class virtual function.
The declaration of D::f ill-formed because it allows all exception, whereas B::f allows only int and double.
Similarly, any function or pointer to function assigned to, or initializing, a pointer to function shall only allow exceptions that are allowed by the pointer or function being assigned to or initialized.
___________________________________
Less is More (Robert Browning)
___________________________________
Less is More (Robert Browning)
댓글 달기