Replies: 33 comments 1 reply
-
Presumably the second #pragma was meant to be enable? I understand it would be interesting, but what advantage would it provide? |
Beta Was this translation helpful? Give feedback.
-
This would essentially be a syntactic sugar for try
{
Validate();
}
catch (MyException)
{
} As exceptions are runtime beasts and preprocessor directives are not. I'm not sure why you would need this. Or why you would do it with preprocessor directives. |
Beta Was this translation helpful? Give feedback.
-
This would codify and encourage very poor exception handling practices. Even if this functionality were added your example still couldn't compile as |
Beta Was this translation helpful? Give feedback.
-
@HaloFour Situation number 1
Situation number 2
Conclusion |
Beta Was this translation helpful? Give feedback.
-
The C# compiler can't stop exceptions from happening. At most it could silently handle the exceptions at the call-site. This behavior that you're requesting would be impossible to accomplish without CLR changes, and considering that it effectively breaks every rule that exists regarding good exception handling that's certainly never going to happen. |
Beta Was this translation helpful? Give feedback.
-
@srburton I'm curious as to why you think C# should add a feature that will allow for horrible horrible coding practices and lead to even more bugs. #pragma disable exception
int x = GetX();
#pragma enable exception The exception would've been thrown, but the |
Beta Was this translation helpful? Give feedback.
-
@HaloFour |
Beta Was this translation helpful? Give feedback.
-
@willard720 The value of the variable would be |
Beta Was this translation helpful? Give feedback.
-
So any not-definitely-assigned variable has a value of |
Beta Was this translation helpful? Give feedback.
-
I believe #1151 would provide the framework for a much better approach: Suppress<MyException>
{
var value = Validate("string is valid?");
if(value is string)
{
Console.Write(value);
}
} elsewhere... public static void Suppress<TException>(Action a) where TException : Exception
{
try { a(); }
catch (TException) {}
} |
Beta Was this translation helpful? Give feedback.
-
I don't see any reason to invent syntactic sugar via pragmas for what is already available in the language by using Even, the two |
Beta Was this translation helpful? Give feedback.
-
It's an int... |
Beta Was this translation helpful? Give feedback.
-
Is this dependent on another proposal that I haven't seen yet, to add a |
Beta Was this translation helpful? Give feedback.
-
You can write yourself a helper method public TOut TryOrDefault<TException, TOut>(Func<TOut> func) where TException : Exception
{
try {
return func();
} catch (TException) {
return default;
}
} Usage does not look that bad compared to pragmas. It could be even improved a bit by #1349 var value = TryOrDefault<MyException, string>(() => Validate("string is valid?")); |
Beta Was this translation helpful? Give feedback.
-
My idea of #pragma it would be because I like c # developer should have full control the language can't stop me, disable functions that in my business suit not alias rule c # should have a form in run mode can create primitive types and tam bém preprocessor directives so linguem be fully templatable, leave the default the uptight to framework, I love developing hack, virus, spam, and with the c # runtime making it possible to mold that would be an enormous advance as the extension that was a great fucker, now imagine the power of programming c # behavior with the own c # code time. Thinking not in an MVC project or Windows Form more in specific projects and can create .dll that contains these mutants of behavior, this may came to security problem and not rely too much on nuget can get around with signatures that have .dll code that might interfere with the c # mode thinking that it would be interpresantes to disable some features and Frameworks visual ja talk that the framework of support, would be very similar to the operator more with everything from c #. |
Beta Was this translation helpful? Give feedback.
-
I'm also not sure that a well defined implementation of this is even possible. It would need to function as a sort of code generation automatically inserting try-catches but as @HaloFour mentioned any variables declared in these sections would throw wrenches into generating valid code. And even if it could generate valid code, it would be exceedingly difficult for the code following these sections to operate without error considering the unknown state of the variables. |
Beta Was this translation helpful? Give feedback.
-
To my mind a It would require a runtime change that would ignore any exception being thrown, and just continue execution straight on. So call Math.Sqrt on a negative number? It'll loop forever. Pass an index to an array that's greater than the length of the array? You access some random uninitialised data. In other words, this is one of the stupidest, most dangerous ideas I have ever seen. And completely infeasible as well. |
Beta Was this translation helpful? Give feedback.
-
@YairHalberstadt |
Beta Was this translation helpful? Give feedback.
-
As we can see in this case it would be nice to give a ignore exception at IDE level because it is a controllable error. |
Beta Was this translation helpful? Give feedback.
-
Are you suggesting you just want to disable debugger breakpoints for exceptions within your segments? |
Beta Was this translation helpful? Give feedback.
-
Yes, I want to because I already have treatment on my cath right down then that ignore would throw the exception for the previous treatment... |
Beta Was this translation helpful? Give feedback.
-
@srburton i can't parse that. Can you repeat what you're trying to say? |
Beta Was this translation helpful? Give feedback.
-
You're in a delegate. The surrounding try/catch has no bearing on what goes on in that delegate. |
Beta Was this translation helpful? Give feedback.
-
Now that I'm in time to explain my idea would be basically this that from the beginning I want to communicate. |
Beta Was this translation helpful? Give feedback.
-
@srburton i have no idea how that would work. Why would the first exception go to the first catch block, and the second exception would go to the second catch block? |
Beta Was this translation helpful? Give feedback.
-
This is the normal situation that we all know today, I did a treatment with an alert ja and when I give an exception within a delegate that execption of a warning in Visual Studio the #pragma would be to disable this warning that Visual Studio and continue the Code because it is an exception that has already been handled Sugestion: |
Beta Was this translation helpful? Give feedback.
-
When placed #pragma he simply ignores continues because he knows he has a treatment before breaking the code. |
Beta Was this translation helpful? Give feedback.
-
I don't know what this means at all. What does it mean to "ignores continues"...
If you want to disable things then uncheck this: You may also want to uncheck: -- Your complaints seem to be entirely about the debugger and how it works. They dont' seem to have any connection to the language at all. |
Beta Was this translation helpful? Give feedback.
-
I think he wants a #pragma to disable the debugger breaking on exceptions in certain code paths. |
Beta Was this translation helpful? Give feedback.
-
@srburton Debugger requests can be made over at |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
It would be interesting if you had a way to ignore exception without needing the try {} cath (Exception) {} By putting this policy.
Beta Was this translation helpful? Give feedback.
All reactions