How to log all thrown exceptions?

I guess the feature you are searching for is called FirstChanceException and can be accessed via the AppDomain.FirstChanceException Event Essentially this event provides a hook to get information about any (managed) exception getting thrown in the AppDomain. You can not handle the Exception this way! It is only a sort of notification Update: regarding your … Read more

How do you handle resources in MATLAB in an exception safe manner? (like “try … finally”)

I would suggest checking out ONCLEANUP objects. They allow you to automatically run code on exit from a function (more specifically, when the ONCLEANUP object is cleared from memory). Loren from The MathWorks discusses this in one of her blog posts here. If you place your above code in a function, it might look something … Read more

Is it okay to throw NullPointerException programmatically? [closed]

I would recommend you never throw NullPointerException by yourself. The main reason not to do this, as Thorbjørn Ravn Andersen says in a comment below, is that you don’t wan’t to mix ‘real, bad NPEs’ with NPEs thrown intentionally. So, until you’re confident that you’re able to recognize ‘valid’ NPE, I’d recommend to use IllegalArgumentException … Read more

Why GCC compiled C program needs .eh_frame section?

First of all, the original reason for this was largely political – the people who added DWARF-based unwinding (.eh_frame) wanted it to be a feature that’s always there so it could be used for implementing all kinds of stuff other than just C++ exceptions, including: backtrace() __attribute__((__cleanup__(f))) __builtin_return_address(n), for n>0 pthread_cleanup_push, implemented in terms of … Read more

What is the difference between `throw new Error` and `throw someObject`?

The difference between ‘throw new Error’ and ‘throw someObject’ in javascript is that throw new Error wraps the error passed to it in the following format − { name: ‘Error’, message: ‘String you pass in the constructor’ } The throw someObject will throw the object as is and will not allow any further code execution … Read more

Scope of exception object in C++

When a throw expression is evaluated, an exception object is initialized from the value of the expression. The exception object which is thrown gets its type from the static type of the throw expression ignoring any const and volatile qualifiers. For class types this means that copy-initialization is performed. The exception object’s scope is outside … Read more