C# Recipe for uncatchable exception
-
Actually, when you think about it, actually managing to catch an exception in an exception handler that is itself creating a stack overflow, well, that would be impressive.
Latest Article - Building a Prototype Web-Based Diagramming Tool with SVG and Javascript Learning to code with python is like learning to swim with those little arm floaties. It gives you undeserved confidence and will eventually drown you. - DangerBunny Artificial intelligence is the only remedy for natural stupidity. - CDP1802
Perhaps, indeed. But that would still be handy! :)
A new .NET Serializer All in one Menu-Ribbon Bar Taking over the world since 1371!
-
Eddy Vluggen wrote:
All of them using recursion? :)
quick questwion, how many method in your code use recusion right now? are you sure? Yeah, just as I thought! ;P
A new .NET Serializer All in one Menu-Ribbon Bar Taking over the world since 1371!
Two in the current codebase. Yes, very sure, as I wrote it. Are you saying you are unsure of what code you are writing? :laugh:
Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^] "If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
-
I had the following code in my app. Turns out you just CAN'T debug that code. At least with Visual Studio 2017, It will crash your process instantly and you will be left without any clue as to what was wrong!! Gotta report that to Microsoft.. Meanwhile, behold the evilest safe C# code that can be!
class Program { static void Main(string\[\] args) { try { Fail(); } catch (Exception ex) { Log(ex); } } static void Fail() { throw new NotSupportedException("You Fool!"); } static void Log(Exception ex) { var sb = new StringBuilder(); Log(ex); Console.WriteLine($"Problem: {sb}"); } }
[EDIT] To clarify, of course this code is buggy, it's a bug repro. But most remarkably the program just crash without hint from Visual Studio. Even if you ask Visual Studio to stop on StackOverflowException, it won't! [EDIT2] Setting breakpoints is not the problem... But why would you put a breakpoint there if you didn't know the bug was there in the first place? FYI it's about 1 month of work before this bug came to light!
A new .NET Serializer All in one Menu-Ribbon Bar Taking over the world since 1371!
I'm using VS2017 and it works as expected
If it's not broken, fix it until it is. Everything makes sense in someone's mind. Ya can't fix stupid.
-
I'm using VS2017 and it works as expected
If it's not broken, fix it until it is. Everything makes sense in someone's mind. Ya can't fix stupid.
-
CodeWraith wrote:
Would you expect one of the self driving cars to bring you to the hospital after hitting a tree?
That's a great analogy. The creation of good strong analogies which lead others to understand things is indication of superior intelligence. Did you steal that analogy from someone else? :rolleyes: See how I set you up? The creation of a setup with an ending punch line is an indication of genius. Someone else gave me the set up and punchline. :laugh: See how I used self-deprecating humor here? It's an indication of superior genius. :laugh:
raddevus wrote:
Did you steal that analogy from someone else? :rolleyes:
No. What do you think? I just have some experience with hitting trees with cars.
I have lived with several Zen masters - all of them were cats. His last invention was an evil Lasagna. It didn't kill anyone, and it actually tasted pretty good.
-
raddevus wrote:
Did you steal that analogy from someone else? :rolleyes:
No. What do you think? I just have some experience with hitting trees with cars.
I have lived with several Zen masters - all of them were cats. His last invention was an evil Lasagna. It didn't kill anyone, and it actually tasted pretty good.
-
I had the following code in my app. Turns out you just CAN'T debug that code. At least with Visual Studio 2017, It will crash your process instantly and you will be left without any clue as to what was wrong!! Gotta report that to Microsoft.. Meanwhile, behold the evilest safe C# code that can be!
class Program { static void Main(string\[\] args) { try { Fail(); } catch (Exception ex) { Log(ex); } } static void Fail() { throw new NotSupportedException("You Fool!"); } static void Log(Exception ex) { var sb = new StringBuilder(); Log(ex); Console.WriteLine($"Problem: {sb}"); } }
[EDIT] To clarify, of course this code is buggy, it's a bug repro. But most remarkably the program just crash without hint from Visual Studio. Even if you ask Visual Studio to stop on StackOverflowException, it won't! [EDIT2] Setting breakpoints is not the problem... But why would you put a breakpoint there if you didn't know the bug was there in the first place? FYI it's about 1 month of work before this bug came to light!
A new .NET Serializer All in one Menu-Ribbon Bar Taking over the world since 1371!
Are you catching exceptions when they are thrown or only after they are dealt with? If it is the latter, I think that even if you want to catch StackOverflowException's, it will not work because there's no more stack to let you do anything and it is probably using something like Environment.FailFast(). [Environment.FailFast Method (String) (System)](https://msdn.microsoft.com/en-us/library/ms131100(v=vs.110).aspx)
-
CodeWraith wrote:
Would you expect one of the self driving cars to bring you to the hospital after hitting a tree?
That would be a handy feature! :-D
A new .NET Serializer All in one Menu-Ribbon Bar Taking over the world since 1371!
Would be a handy feature, if it stops hittings trees on the way to the hospital.
-
Two in the current codebase. Yes, very sure, as I wrote it. Are you saying you are unsure of what code you are writing? :laugh:
Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^] "If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
Your codebase must be a one man small project then.. or you have prodigious memory... (or young maybe?) Further this method was not even mean to be recursive.. it's just I got 2 method with the same name but different parameter, just accidentally forgot the extra parameter.. BTW I believe there are 0 recursion in my app but who knows... there was this accidental one for instance...
A new .NET Serializer All in one Menu-Ribbon Bar Taking over the world since 1371!
-
Are you catching exceptions when they are thrown or only after they are dealt with? If it is the latter, I think that even if you want to catch StackOverflowException's, it will not work because there's no more stack to let you do anything and it is probably using something like Environment.FailFast(). [Environment.FailFast Method (String) (System)](https://msdn.microsoft.com/en-us/library/ms131100(v=vs.110).aspx)
Paulo Zemek wrote:
Are you catching exceptions when they are thrown or only after they are dealt with?
What does that means? I mean what does "catching exception after they are dealt with" means?
A new .NET Serializer All in one Menu-Ribbon Bar Taking over the world since 1371!
-
Your codebase must be a one man small project then.. or you have prodigious memory... (or young maybe?) Further this method was not even mean to be recursive.. it's just I got 2 method with the same name but different parameter, just accidentally forgot the extra parameter.. BTW I believe there are 0 recursion in my app but who knows... there was this accidental one for instance...
A new .NET Serializer All in one Menu-Ribbon Bar Taking over the world since 1371!
Super Lloyd wrote:
Your codebase must be a one man small project then.. or you have prodigious memory... (or young maybe?)
None of those three.
Super Lloyd wrote:
Further this method was not even mean to be recursive.. it's just I got 2 method with the same name but different parameter, just accidentally forgot the extra parameter..
That's why we have logging :)
Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^] "If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
-
Super Lloyd wrote:
Your codebase must be a one man small project then.. or you have prodigious memory... (or young maybe?)
None of those three.
Super Lloyd wrote:
Further this method was not even mean to be recursive.. it's just I got 2 method with the same name but different parameter, just accidentally forgot the extra parameter..
That's why we have logging :)
Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^] "If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
well.. it was a bug in the logging class, if you must know...
A new .NET Serializer All in one Menu-Ribbon Bar Taking over the world since 1371!
-
Super Lloyd wrote:
Your codebase must be a one man small project then.. or you have prodigious memory... (or young maybe?)
None of those three.
Super Lloyd wrote:
Further this method was not even mean to be recursive.. it's just I got 2 method with the same name but different parameter, just accidentally forgot the extra parameter..
That's why we have logging :)
Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^] "If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
Eddy Vluggen wrote:
Super Lloyd wrote:
Your codebase must be a one man small project then.. or you have prodigious memory... (or young maybe?)
None of those three.
Ha! I was already old when the earth was young!
A new .NET Serializer All in one Menu-Ribbon Bar Taking over the world since 1371!
-
Eddy Vluggen wrote:
Super Lloyd wrote:
Your codebase must be a one man small project then.. or you have prodigious memory... (or young maybe?)
None of those three.
Ha! I was already old when the earth was young!
A new .NET Serializer All in one Menu-Ribbon Bar Taking over the world since 1371!
No, but experienced enough to add a hint in XML comment when recursion is used. Logging is easily tested with unit-tests. Anything else? :)
Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^] "If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
-
No, but experienced enough to add a hint in XML comment when recursion is used. Logging is easily tested with unit-tests. Anything else? :)
Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^] "If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
Yeah, you should work on your communication skills. Also, most of this codebase is written for being hard to test. One of the thing I am changing. Though I was not planning to using test every single method or allegedly trivial ones... nor every single parameter... (more than a bazillion possible combination there) Beside my fake test application with all the real code except fake - virtual faster hardware was also crashing mysteriously. Bummer.
A new .NET Serializer All in one Menu-Ribbon Bar Taking over the world since 1371!
-
Yeah, you should work on your communication skills. Also, most of this codebase is written for being hard to test. One of the thing I am changing. Though I was not planning to using test every single method or allegedly trivial ones... nor every single parameter... (more than a bazillion possible combination there) Beside my fake test application with all the real code except fake - virtual faster hardware was also crashing mysteriously. Bummer.
A new .NET Serializer All in one Menu-Ribbon Bar Taking over the world since 1371!
Super Lloyd wrote:
Yeah, you should work on your communication skills.
I don't work in marketing.
Super Lloyd wrote:
Also, most of this codebase is written for being hard to test. One of the thing I am changing.
I'd expect a logger to be some independent item, or even framework.
Super Lloyd wrote:
Though I was not planning to using test every single method or allegedly trivial ones... nor every single parameter... (more than a bazillion possible combination there)
Depending on how large the code-base is, testing everything is rather unrealistic. And yes, brownfields are the prime source for material for the Weird & Wonderfull forum here :)
Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^] "If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
-
Paulo Zemek wrote:
Are you catching exceptions when they are thrown or only after they are dealt with?
What does that means? I mean what does "catching exception after they are dealt with" means?
A new .NET Serializer All in one Menu-Ribbon Bar Taking over the world since 1371!
You can debug exceptions when they are thrown. This means you stop even if there's a catch block that's going to "eat" the exception. Or, you can debug only exceptions that are uncaught or are rethrown. In this case, if there's a catch clause, you will not see the exception until it is rethrown (if it ever is rethrown). Usually on the second case, an exception that kills the application will not give you a chance to debug it. On the first case, you usually have that option (and for an exception throwing another exception, throwing another exception you would be bothered thousand of times before the app is killed).