klein / klein.php

A fast & flexible router
MIT License
2.66k stars 290 forks source link

error() breaks when exception code isn't an int #298

Open jk3us opened 9 years ago

jk3us commented 9 years ago

https://github.com/chriso/klein.php/blob/master/src/Klein/Klein.php#L931

throw new UnhandledException($msg, $err->getCode(), $err);

I'm not exactly the mechanism this got called, but it got called when I had a PDO Exception. The problem is that getCode on a PDOException doesn't always return an int. This is mentioned at https://secure.php.net/manual/en/exception.getcode.php. "Returns the exception code as integer in Exception but possibly as other type in Exception descendants (for example as string in PDOException)."

So instead of my global exception handler telling me what went wrong, I got an error about a Wrong parameters passed to the Exception constructor. Maybe just rethrow the same exception instead of wrapping it in an UnhandledException, which might other important info in the original?

jonahgeorge commented 8 years ago

@jk3us Did you have any luck resolving this? I'm experiencing the same issue.

jk3us commented 8 years ago

I don't think I ever did. After figuring out which exception was causing the problem, I fixed the error in my sql query and haven't had to deal with it since. Sorry.