XML が無効な場合、SimpleXML は例外をスローします。
$xml = '<root><element>bad</element></root';
$sxml = new SimpleXMLElement($xml);
出力
<br />
<b>Warning</b>: SimpleXMLElement::__construct(): Entity: line 1: parser error : expected '>' in <b>[...][...]</b> on line <b>2</b><br />
<br />
<b>Warning</b>: SimpleXMLElement::__construct(): <root><element>bad</element></root in <b>[...][...]</b> on line <b>2</b><br />
<br />
<b>Warning</b>: SimpleXMLElement::__construct(): ^ in <b>[...][...]</b> on line <b>2</b><br />
<br />
<b>Fatal error</b>: Uncaught exception 'Exception' with message 'String could not be parsed as XML' in [...][...]:2
Stack trace:
#0 [...][...](2): SimpleXMLElement->__construct('<root><element>...')
#1 {main}
thrown in <b>[...][...]</b> on line <b>2</b><br />