I'm wondering if there is a tool to find uncaught exceptions in C# using static code analysis? Basically I want to select a methodA() and want a list of all exceptions thrown by methodA() and all methods called by methodA(). I tried ReSharper + Agent Johnson and AtomineerUtils, both fail this simple task.
Here's my example code:
public class Rectangle
{
public int Width { get; set; }
public int Height { get; set; }
public int Area()
{
CheckProperties();
long x = Width * Height;
if (x > 10)
throw new ArgumentOutOfRangeException();
return (int) x;
}
private void CheckProperties()
{
if (Width < 0 || Height < 0)
throw new InvalidOperationException();
}
}
The tool should be able to tell me (in any form) that method Area() will throw ArgumentOutOfRangeException
or InvalidOperationException.
If an exception is not caught, it is intercepted by a function called the uncaught exception handler. The uncaught exception handler always causes the program to exit but may perform some task before this happens.
CWE 248-Uncaught Exception occurs when an exception is not caught by a programming construct or by the programmer, it results in an uncaught exception. In Java, for example, this would be an unhandled exception that would terminate the program.
It allow us to handle the exception use the keywords like try, catch, finally, throw, and throws. When an uncaught exception occurs, the JVM calls a special private method known dispatchUncaughtException( ), on the Thread class in which the exception occurs and terminates the thread.
An unhandled exception is an error in a computer program or application when the code has no appropriate handling exceptions. Learn about the definition and examples of unhandled exceptions, and explore programming and exception handlers. Updated: 01/04/2022.
I used an R# addin once that did that in the IDE - Exceptional. Bad idea, turns out that it complains about every single string.Format call and similar common cases that may indeed throw, but that won't cause issues.
Decide for yourself if it's worth it: https://github.com/CSharpAnalyzers/ExceptionalReSharper
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With