C
C#3y ago
surwren

exception subclass for try-catch block [Answered]

I want to subclass Exceptions to create a class that can be inserted into a catch() parameter to detect errors. (Say for example I want an exception class that can detect if a triangle is valid) I looked through the microsoft libraries' source code for some inkling of a conditional that logically allows for something like catch(DivideByZeroException) but could not find anything that made sense to me. I'm dumbfounded. Without conditionals, how else does catch() detect which exception is being thrown?
5 Replies
surwren
surwrenOP3y ago
Ok but what if my condition doesn't normally throw an exception Like the compiler won't normally throw an exception for triangle of sides a,b,c if a+b<c Do I need to manually throw an exception each time?
Saber
Saber3y ago
of course, if its not an exception that the language or libraries you are using are going to be throwing for you, you will have to throw them yourself were applicable.
surwren
surwrenOP3y ago
I see I have completely misunderstood the flow of the throw-catch process thanks!
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
Accord
Accord3y ago
✅ This post has been marked as answered!

Did you find this page helpful?