✅ Issue with try/catch block
I am trying to catch an exception, null the bad value, and throw the exception again so the code that calls this function can handle it. I've attached screenshots of both sections of code. It's saying that the exception is unhandled even though I am using try/except blocks to catch SshAuthenticationException in both. Changing the exception to catch just Exception does not fix this. I must be missing something here.


10 Replies
Why do you say it doesn't catch it? Have you continued the execution?
On a side note though: Exception driven logic is generally bad. I'd suggest going another route.
It's appealing initially, but you have a big perf hit for not that much gains.
Continuing execution at that point just ended the debug session. Launching without debugging led to the UI not even opening. I say its not catching it because the errors visual studio are showing me via the debug say that its unhandled by the user, but im running it in a catch block and its...not catching it apparently. I did make sure the exception class was correct
I'm not talking about full continuing. If you go step by step at that point, what happens?
Oh thats good to know. I've done this in Python a lot.
For this method specifically, you could rename it
TryInitializeConnection
and return a bool of whether or not it did.
But to go back on your issue, once you hit the exception, what happens if you press F10 a few times?I am working on reproducing the issue, for some reason its seeming to work now? Gonna keep testing it.
Because right now, you're in what's called "Break on exception". Even if it's handled (by your try-catch) it will Break, but then you can continue and it will jump in the catch, then throw again, then go up a level, etc, etc., until it's caught, or the program exits.
Okay I think I was confused by how the debugger works. I am new to VS. Anyways this is going to sound stupid but it seems to work now even though I haven't changed that code since I posted it. It's not breaking on me throwing any exceptions now. They're handled, and I believed they were handled when I posted this thread. Now the debugger isnt saying anything.
I personally always work in "Break on exception" mode to see the exception happening live, where they're thrown.
Anyhow, if your issue comes back, feel free to post again 🙂
Okay! I will have to learn more about the debugger, seems very helpful and this may have just been me not having any idea what I'm doing lol
Thanks for the help! im going to close this thread now cause I'm not having the issue anymore.