Try And Catch - For Exception Handling only?

BlitzMax Forums/BlitzMax Programming/Try And Catch - For Exception Handling only?

beanage(Posted 2011) [#1]
Hey,

just had an awkward idea designing a search Algorithm, and would be interested in what you guys think about it.

It runs like this:
Iterate though all elements in the result list
  TRY
    If the element doenst fit the search parameter A
      THROW Exception A
    If the element doenst fit the search parameter B
      THROW Exception B
    ...
  CATCH Exception
    Remove the element from the result list and tell why


On a more abstract level, wouldn't TRY-CATCH eat up the tiny bit of GOTO that is still legimite to use that way?

Last edited 2011


Czar Flavius(Posted 2011) [#2]
Try catch is meant to be used for error handling, and not bread-and-butter code. An interesting experiment, but I wouldn't use it in a real project. You could do this with if statements, a variable to record the reason (0=A, 1=B) and Exit the loop when finding a match.

Last edited 2011


beanage(Posted 2011) [#3]
bread-and-butter code

I was actually afraid somebody would say that =) .. but who am I kidding, you are propably right.


Czar Flavius(Posted 2011) [#4]
Go for it if you want to, but what do you do if your catches start catching real errors :p


ima747(Posted 2011) [#5]
Always nice to take a different look at a problem, but like czar said, you're opening the door to unexpected behavior since you can't guarantee that nothing else will throw an exception at that point (unlikely though it is). Tighter code is easier to manage code and else if statements will have the same effect (breaking the test string when a condition is met) without opening a hole.


Azathoth(Posted 2011) [#6]
In other programming languages exception handling involves more than just jumping to catch statements (like stack unwinding), and is considered bad practice to use for non-errors. I imagine the same would be with BlitzMax.