End end

The output of this call is the following:

Message: Another ToString: Another Hello

BaseException Message: Hello InnerException Message: Hello

There are two relevant elements to notice. The first is that in the case of a single nested exception the BaseException property and the InnerException property both refer to the same exception object, the original one. The second is that while the message of the new exception contains only the actual message, by calling ToString you get access to the combined messages of all the nested exceptions, separated by an sLineBreak (as you can see in the code of the method Exception. ToString). The choice of using a line break in this case produces an odd output, but once you know about it you can format it the way you like, replacing the line breaks with a symbol of your choice or assigning them to the Text property of a string list.

As a further example, let me show you what happens when raising two nested exceptions. This is the new method:

procedure TFormExceptions.MethodWithTwoNestedExceptions; begi n try raise Exception.Create ('Hello'); except begi n try

  1. RaiseOuterException ( Exception.Create ('Another')); except
  2. RaiseOuterException ( Exception.Create ('A third'));

This called is a method that is identical to the one we saw previously and produces the following output:

Message: A third ToString: A third Another Hello

BaseException Message: Hello InnerException Message: Another

This time the BaseException property and the InnerException property refer to different objects and the output of ToString spans three lines.

Was this article helpful?

0 0
Project Management Made Easy

Project Management Made Easy

What you need to know about… Project Management Made Easy! Project management consists of more than just a large building project and can encompass small projects as well. No matter what the size of your project, you need to have some sort of project management. How you manage your project has everything to do with its outcome.

Get My Free Ebook


Post a comment