# perldoc > XML::LibXML::Error

---
type: CommandReference
command: XML::LibXML::Error
mode: perldoc
section: 
source: perldoc
---

## Quick Reference
- `eval { ... }; if (ref($@)) { ... }` — Catch structured error
- `$@->as_string()` — Serialize error to string
- `$@->dump()` — Dump all fields
- `$@->domain()` — Get error domain
- `$@->code()` — Get error code
- `$@->level()` — Get error level (0-3)
- `$@->file()` — Get filename
- `$@->line()` — Get line number

## Name
Structured Errors

## Synopsis
perl
eval { ... };
if (ref($@)) {
    # handle structured error
} elsif ($@) {
    # non-structured error
} else {
    # no error
}

$XML::LibXML::Error::WARNINGS = 1;
$message = $@->as_string();
print $@->dump();
$domain = $@->domain();
$code   = $@->code();
$msg    = $@->message();
$level  = $@->level();
$file   = $@->file();
$line   = $@->line();
$node   = $@->nodename();
$str1   = $@->str1();
$str2   = $@->str2();
$str3   = $@->str3();
$num1   = $@->num1();
$num2   = $@->num2();
$string = $@->context();
$offset = $@->column();
$prev   = $@->_prev();
## Options
- `$XML::LibXML::Error::WARNINGS` — Set to 1 to report warnings via `warn`, 2 via `die`
- `$@->as_string()` — Full error message (overloaded `""`)
- `$@->dump()` — All fields as `'name' => 'value'` lines
- `$@->domain()` — Error domain (e.g., "parser", "validity", "XPath")
- `$@->code()` — libxml2 error code (see `XML::LibXML::ErrNo`)
- `$@->message()` — Human-readable error message
- `$@->level()` — Error severity: 0=none, 1=warning, 2=error, 3=fatal
- `$@->file()` — Filename being processed
- `$@->line()` — Line number
- `$@->nodename()` — Node name where error occurred
- `$@->str1()`, `$@->str2()`, `$@->str3()` — Extra string info
- `$@->num1()`, `$@->num2()` — Extra numeric info (`num2` often column number)
- `$@->context()` — ~80 characters of XML near parsing error
- `$@->column()` — Offset within context
- `$@->_prev()` — Previous `XML::LibXML::Error` object if chained

## Examples
perl
use XML::LibXML;
use XML::LibXML::Error;
$XML::LibXML::Error::WARNINGS = 1;

my $parser = XML::LibXML->new();
eval {
    my $doc = $parser->parse_string('<root>');
};
if ($@) {
    print "Error: ", $@->as_string();
    print "Domain: ", $@->domain();
    print "Code: ", $@->code();
    print "Line: ", $@->line();
}
## See Also
- [XML::LibXML](http://localhost/phpMan.php/perldoc/XML::LibXML/markdown)
- [XML::LibXML::ErrNo](http://localhost/phpMan.php/perldoc/XML::LibXML::ErrNo/markdown)