Catching access violation exceptions?

Read it and weep! I figured it out. If you don’t throw from the handler, the handler will just continue and so will the exception. The magic happens when you throw you own exception and handle that. #include “stdafx.h” #include <stdio.h> #include <stdlib.h> #include <signal.h> #include <tchar.h> void SignalHandler(int signal) { printf(“Signal %d”,signal); throw “!Access … Read more

Logging uncaught exceptions in Python

Here’s a complete small example that also includes a few other tricks: import sys import logging logger = logging.getLogger(__name__) handler = logging.StreamHandler(stream=sys.stdout) logger.addHandler(handler) def handle_exception(exc_type, exc_value, exc_traceback): if issubclass(exc_type, KeyboardInterrupt): sys.__excepthook__(exc_type, exc_value, exc_traceback) return logger.error(“Uncaught exception”, exc_info=(exc_type, exc_value, exc_traceback)) sys.excepthook = handle_exception if __name__ == “__main__”: raise RuntimeError(“Test unhandled”) Ignore KeyboardInterrupt so a console python … Read more

UnauthorizedAccessException cannot resolve Directory.GetFiles failure [duplicate]

In order to gain control on the level that you want, you should probably probe one directory at a time, instead of a whole tree. The following method populates the given IList<string> with all files found in the directory tree, except those where the user doesn’t have access: // using System.Linq private static void AddFiles(string … Read more