Any error message for which you know the number can be converted to a named exception in your code, eg
SQL> declare
2 x xmltype;
3 begin
4 x := xmltype('some junk');
5 end;
6 /
declare
*
ERROR at line 1:
ORA-31011: XML parsing failed
ORA-19213: error occurred in XML processing at lines 1
LPX-00210: expected '<' instead of 's'
ORA-06512: at "SYS.XMLTYPE", line 310
ORA-06512: at line 4
SQL> set serverout on
SQL> declare
2 x xmltype;
3 invalid_xml exception;
4 pragma exception_init(invalid_xml,-31011);
5 begin
6 x := xmltype('some junk');
7 exception
8 when invalid_xml then
9 dbms_output.put_line('This did not work');
10 end;
11 /
This did not work
PL/SQL procedure successfully completed.