CS246 Lecture Notes - Lecture 17: Observer Pattern, In C
Document Summary
// for a specific exception catch (someexception s) throw someotherexception{ }; Any code in the try block, the program skips to the catch block which is expected to handle it. throw s vs throw. What if the acual exception that was originally thrown was a [subclass/subtype] of the exception (someexception) i caught? throw s would cause object slicing. throw throws the exact object again and is thus preferred. All c++ library exceptions are derived from the exception class. C++ does not require user-defined exceptions to be derived from the exception class. In c++ you can throw anything - int/ bool etc. git pull refactt. cc/efact. cc git pill refib. cc/exfib/cc. Exceptions should be only used for error situations. Advice: create your own exception classes or reuse existing ones. Use abstract base class to define the interface. Use pointers to the base class and never pointer to the subclass [ use the virtual methods.