Check Unhandled Exception .NET 4 - exception

I would know what are the Exception that i didnt handle , even if doesn't throw any exception at the moment, in my Winform Program.
Is there a way to do with .Net 4?
I already made some research about this, but all software that i found doesnt support .NET4.
Update: I need a way to know Which are the Exception that i Didnt Handle. Just like Exception-Hunter but it doesnt support .NET 4 more.
Thanks
Edit: Updated Question

Unfortunately, there is no sure way do what you are asking, unless you never call any third-party code, including .NET framework methods. Unlike Java, .NET has no concept of "checked" exceptions. So, the only way to know with 100% certainty what exceptions a given piece of code can throw is to read the code.

Related

Why should I use Assert.IsNull in Sitecore?

I've seen a lot of code in Sitecore where Assert.IsNull is used before any logic;
e.g.
Database database = Factory.GetDatabase(itemUri.DatabaseName);
Assert.IsNotNull(database, itemUri.DatabaseName);
return database.GetItem(attribute);
Could someone help me understand why I would use this?
This topic isn't really specific to Sitecore, even though in this case the assert methods are within the Sitecore library.
In general, assertions are used to ensure your code is correct during development, and exception handling makes sure your code copes in unpredictable circumstances.
Take a look at these SO questions for some very good explanations.
When to use an assertion and when to use an exception
When to use assert() and when to use try catch?
Here's an article specifically about the use of Sitecore assertions:
http://briancaos.wordpress.com/2012/01/20/sitecore-diagnostics-assert-statements/

Deriving from Exception classes warning: CA2237: Mark ISerializable types with SerializableAttribute

I derived several classes from various exceptions. Now VS gives warning as in the title of this question.
Could someone explain what implications of suppressing this rule?
Could you explain rule from here saying "Do not suppress a warning from this rule for exception classes because they must be serializable to work correctly across application domains."?
P.S. Well I've got an answer myself. You indeed have to mark exceptions as serializable. They work fine without this attribute in same AppDomain. However if you try to catch it from some other domain, it will have to get serialized in order to get across app boundaries. And that is the main reason I found for this.
This is not exactly a Visual Studio warning, it is a warning produced by the FxCop tool. Which you can run from the VS Analyze menu. FxCop is a static analyzer that looks for common gotchas in a .NET program that a compiler won't flag. Most of its warnings are pretty obscure and are rarely really serious problems, you need to treat it as a "have you thought of this?" kind of tool.
The little factoid it is trying to remind you about here is that the Exception class implements ISerializable and has the [Serializable] attribute. Which is a pretty hard requirement, it makes the base Exception object serializable across app-domains. Necessary because Exception doesn't derive from MarshalByRefObject. And necessary to allow code that you run in another app domain to throw exceptions that you can catch.
So FxCop notes that you didn't do the same for your own Exception derived class. Which is really only a problem if you ever intend to have code that throws your exception run in another app-domain. FxCop isn't otherwise smart enough to know if you do so it can only remind you that it goes wrong when you do. It is pretty uncommon so feel free to ignore the warning when you just don't know yet whether you will or not or if it all sounds like Chinese to you.
If you're not going to use multiple AppDomain in your application, I think you can ignore it or suppress.

Cant build project after installing jdk 7

After installing jdk 7 and switching java platform for my project in ide i get this when im trying to build project.
warning: [options] bootstrap class path not set in conjunction with -source 1.6
An annotation processor threw an uncaught exception.
Consult the following stack trace for details.
java.lang.NoSuchMethodError: com.sun.tools.javac.util.Name$Table.instance(Lcom/sun/tools/javac/util/Context;)Lcom/sun/tools/javac/util/Name$Table;
at uk.org.retep.util.javac.JavacUtils.<init>(JavacUtils.java:128)
at uk.org.retep.util.annotation.AnnotationScannerProcessor.process(AnnotationScannerProcessor.java:76)
at com.sun.tools.javac.processing.JavacProcessingEnvironment.callProcessor(JavacProcessingEnvironment.java:793)
at com.sun.tools.javac.processing.JavacProcessingEnvironment.discoverAndRunProcs(JavacProcessingEnvironment.java:722)
at com.sun.tools.javac.processing.JavacProcessingEnvironment.access$1700(JavacProcessingEnvironment.java:97)
at com.sun.tools.javac.processing.JavacProcessingEnvironment$Round.run(JavacProcessingEnvironment.java:1029)
at com.sun.tools.javac.processing.JavacProcessingEnvironment.doProcessing(JavacProcessingEnvironment.java:1163)
at com.sun.tools.javac.main.JavaCompiler.processAnnotations(JavaCompiler.java:1106)
at com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:824)
at com.sun.tools.javac.main.Main.compile(Main.java:419)
at com.sun.tools.javac.main.Main.compile(Main.java:333)
at com.sun.tools.javac.main.Main.compile(Main.java:324)
at com.sun.tools.javac.Main.compile(Main.java:76)
at com.sun.tools.javac.Main.main(Main.java:61)
I know that sun switched some apis or something, but ide doesnt tell me whats wrong exactly. Thanks in advance.
You should really share your code that's causing the exception, but the exception indicates that you're using an internal Java API (any class contained in the com.sun packages). You shouldn't be using those APIs directly, as they're considered private implementations and subject to change. As those APIs are private, it isn't as simple as looking for the Javadoc to see what methods are available, but suffice it to say that the method you're calling doesn't exist. You have a few options:
If you're calling this method directly, you need to refactor. You should look for ways to accomplish the same work using public APIs.
If this happens after calling a library method, you should file a bug with the library maintainer informing them about the error and the risks of using the com.sun APIs.
If this happens after calling a public Java API (anything in the java or javax packages) then You should file a bug report with Oracle. This one seems unlikely though.
Also, if you share your code, we may be able to better help you.
[edit]
Further, see this page for more information about why you shouldn't use classes in the com.sun packages.

.NET Exception Explorer

Does anyone know of a program or plug-in or anything that I can find out what are all the exceptions any method may throw?
I think JAVA has this build in if I'm not mistaken. Where the compiler tells you what exceptions this method will throw.
Does the same exist for .NET?
Thanks
Edit: After searching around more, I wish there was tool like Object Explorer, except for Exceptions. You select the class or method and it lists the exceptions, at that level, which are thrown by the class. The tool links provided are a great start. Thanks!
I don't know if this is exactly what you are looking for, but:
http://www.red-gate.com/Products/Exception_Hunter/index.htm
Note: I've never used the product, and I don't work for Red Gate, I just remember seeing it advertised before.
You can see this information with intellisense in Visual Studio. When you highlight a method name in the intellisense list, its description should contain a list of exceptions at the bottom. This information is added by properly commenting your methods and classes. If you are using a library that is not part of the framework, then you will only get this information if the developers of the library appropriately commented their code.
.NET doesn't require or permit each method to state which exceptions it throws. As I recall, it was felt that this would lead most developers to simply state "throws Exception".

Forcing application to throw specific exceptions

We are replacing the exception handling system in our app in order to conform to Vista certification, but the problem is how to force certain exceptions to be thrown, so that we can check the response.
Unfortunately the whole app was written without taking into consideration proper layering, abstraction or isolation principles, and within the timeframe introducing mocking and unit testing is out of the question :(
My idea is to introduce code which will throw a particular exception, either through a compiler directive or by respecting a value in the config file. We can then just run the app as normal and manually check how the exception is handled.
Just thought I'd put it out there and see if the SO community can think of anything better!
Cheers
Introduce this code:
throw new Exception("test");
If you need the exception to always be there (i.e., not just test code), then hide it behind a command-line parameter.
C:\Users\Dude> myapp.exe /x
I might not have a clue about this but my first thought was to use aspect oriented programming to throw exceptions when certain code is run. spring.net has support for this, though I don't know how well it works for your purpose. I wouldn't take my word on this but it's something to look into.