throwing exceptions - Programmers Heaven

Howdy, Stranger!

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

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

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

  • zibadianzibadian Posts: 6,349Member
    : 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.
  • Josh CodeJosh Code Posts: 675Member
    thanks, that is what I was looking for.
Sign In or Register to comment.