In this post, we will see how to resolve can only throw exceptions in C# functions?
Question:
I’ve written a custom exception and want it to be thrown when the parking hours exceed 24hrs. I firstly placed the throw exception in the parent class propertyHoursParked
but it never throws when I debug the program. Then I moved it to a function within the same class and it worked fine. Does it mean we can only throw exceptions in a function definition? Hope to get some insights into this as I don’t fully understand the mechanism of exception handling even after researBest Answer:
Well, exceptions are designed for exceptional situations only. In our case it seems that we can have such behavior in theset
only:If you have better answer, please add a comment about this, thank you!
Source: Stackoverflow.com