You searched for exceptions
. We found 601
results in 0.392 seconds.
There are loads of exceptions declared by the .NET framework - and other code (including your own) can create more. There are certainly more than 39.... look at the documentation for System.Exception and you'll see near the bottom a list... more
Yes, constructors can throw exceptions. Usually this means that the new object is immediately eligible for garbage collection (although it may not be collected for some time, of course). It's possible for the "half-constructed" object to... more
I'm on the "not slow" side. I've written two short articles about this. There are criticisms of the benchmark aspect, which are mostly down to "in real life there'd be more stack to go through, so you'd blow the cache etc" - but using... more
When I first started using C# I was scared by this too. Then I found that actually, it doesn't matter very often. I very rarely find that I can catch an exception and so something useful with it anyway... almost all my exceptions bubble up... more
In general, avoid provoking an exception which you could easily have avoided by execution-time testing and which could be a problem for reasons other than a bug elsewhere in your code. If you're going to divide by something and you have... more
No, there's nothing wrong with catching IOException and FileNotFoundException - if you can genuinely handle those exceptions. That's the important bit - can you really proceed in the face of that exception? Sometimes you can - very often... more
Call a projection which has that try/catch: myEnumerable.Select(a => TryThisMethod(a)); ... public static Bar TryThisMethod(Foo a) { try { return ThisMethodMayThrowExceptions(a); } ... more
It's pretty easy to try this for yourself. For example: using System; class Test { static void Main(string[] args) { try { Top(); } catch (Exception e) { ... more
Personally I'm not keen on using assertions for this sort of thing, simply because they can be turned off. Some places use assertions when running tests, but then disable them for production for the sake of speed. To me this is like taking... more
Presumably your method is declared to throw UnsupportedAddressTypeException but not SQLException and ClassNotFoundException. Checked exceptions can only be thrown (including rethrowing an existing one) from methods which declare that they... more