throwing exceptions

How can exceptions be thrown with Delphi?
Is it possible to do so?

I mean like it is done in Java or c++.
Can an object of an exception class be created and thrown so the exception can be handled elsewhere using a try-except on... block?

Comments

  • : How can exceptions be thrown with Delphi?
    : Is it possible to do so?
    :
    : I mean like it is done in Java or c++.
    : Can an object of an exception class be created and thrown so the exception can be handled elsewhere using a try-except on... block?
    :
    In Delphi you can use the word raise to raise (=throw) an exception. Here is a simple example:
    [code]
    if j = 0 then
    raise EMyMathError.Create('Cannot divide by 0')
    else
    Result := i div j;
    [/code]
    This will be nearly the same as:
    [code]
    Result := i div j;
    [/code]
    except that the exception has different class and text.
  • thanks, that is what I was looking for.
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories