Difference between a C++ exception and Structured Exception

You actually have three mechanisms: C++ exceptions, implemented by the compiler (try/catch) Structured Exception Handling (SEH), provided by Windows (__try / __except) MFC exception macros (TRY, CATCH – built on top of SEH / C++ exceptions – see also TheUndeadFish’s comment) C++ exceptions usually guarantee automatic cleanup during stack unwinding (i.e. destructors of local objects … Read more

Try-catch-finally and then again a try catch

Write a SQLUtils class that contains static closeQuietly methods that catch and log such exceptions, then use as appropriate. You’ll end up with something that reads like this: public class SQLUtils { private static Log log = LogFactory.getLog(SQLUtils.class); public static void closeQuietly(Connection connection) { try { if (connection != null) { connection.close(); } } catch … Read more

Catching exception in context manager __enter__()

Like this: import sys class Context(object): def __enter__(self): try: raise Exception(“Oops in __enter__”) except: # Swallow exception if __exit__ returns a True value if self.__exit__(*sys.exc_info()): pass else: raise def __exit__(self, e_typ, e_val, trcbak): print “Now it’s running” with Context(): pass To let the program continue on its merry way without executing the context block you … Read more