mustangostang / spyc

A simple YAML loader/dumper class for PHP
MIT License
701 stars 207 forks source link

Error handling #40

Closed rilwis closed 7 years ago

rilwis commented 9 years ago

Hi, I'd like to ask if there's a way to handle errors when parsing file? Sometimes the file or string has incorrect syntax and throw a Fatal error is not quite friendly. We need something like try...catch to make the web still works and we can show error message somehow.

Thanks.

jackmcdade commented 7 years ago

Try and catch is the right way to do it. It goes on your site of the application though, not as part of the Spyc package.

try {
    Spyc::YAMLLoad('spyc.yaml');
} catch (Exception $e) {
    // do something with $e->getMessage();
}