I want to throw an exception at next catch, (I attached image)
Anybody know how to do this?
When an exception is cached in a catch block, you can re-throw it using the throw keyword (which is used to throw the exception objects). Or, wrap it within a new exception and throw it.
If a catch block cannot handle the particular exception it has caught, you can rethrow the exception. The rethrow expression ( throw without assignment_expression) causes the originally thrown object to be rethrown.
It's fine practice to throw in the catch block. It's questionable practice to do so ignoring the original exception.
In C++, inside catch block we can re-throw an exception using throw statement, but the thrown exception should have the same type as the current caught one.
C# 6.0
to the rescue!
try { } catch (Exception ex) when (tried < 5) { }
You can't, and trying to do so suggests that you've got too much logic in your catch
blocks, or that you should refactor your method to only do one thing. If you can't redesign it, you'll have to nest your try
blocks:
try { try { ... } catch (Advantage.Data.Provider.AdsException) { if (...) { throw; // Throws to the *containing* catch block } } } catch (Exception e) { ... }
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