0

I have a form factory class that builds the form based on data in an array.

Each element is represented as a class as well.

The form elements each have a toString implementation that spits out the html for that kind of element and the form itself has a toString implementation that simply folds it's array of elements into a string.

My problem is that when there is an error I simply get 'toString cannot through an exception' which is really not much help when the form element in question has two parent classes. ConcreteFormElement >> OptionFormElement >> Select ( a dropdown ). The error could be anywhere in between.

This is a WordPress theme and I'm doing it entirely using OOP practice mainly as an excercise for learning.

It seems only natural to me to use toString but the print_f debugging is getting me down. Am I doing something wrong? Should I forget about toString? Or is there someway to debug easier?

P.S. Is the question too vague?

4

1 回答 1

0

Basically, within each __toString() you need to wrap your code in a try catch, and in the catch statement you could "return the string representing the exception". That way the parent toString calls won't fail...and you can then manipulate the string as you see fit.

于 2013-09-13T16:33:14.473 回答