Question: I recently switched from MySQL to PostgreSQL. I have one problem left however.

Previously, I would store small images in the BLOB format in MySQL.

PostgreSQL doesn't know such thing as a BLOB.

I tried using BYTEA field type instead. This actually inserts an large (hexadecimal?) string I guess, but now I'm stuck trying to get this string back to displaying an actual image in PHP..

Any ideas? Thanks in advance.

Here is a piece of code I use to save the image in the database:

```
$data = bin2hex(file_get_contents('php://input'));

if (!empty($data)) {
  $sql = "UPDATE asset SET data = X'%s' WHERE uuid = '%s'";
  $args = array($data, $asset_uuid);
}

```

psql (9.1.3) and php 5.3.6 are used

Answer: 
Yours is the second question I've seen today asking about this.

No, it's perfectly appropriate to catch this exception.

And it's *definitely* better form to catch a *more explicit* exception (like "NumberFormatException") than a generic "Exception".

IMHO...

PS:
*Where* you put the exception: at this level, or higher-up, is a different question.

The rule of thumb is "the lowest level where you know what happened, and how best to recover."

Or, to put it differently (quoting from a link below):

"A method should only catch an exception when it can handle it in some sensible way."

Here's some discussion:

* [At what level and how is appropriate to catch exceptions](https://stackoverflow.com/questions/10977482/at-what-level-and-how-is-appropriate-to-catch-exceptions)
* [Why should I not wrap every block in "try"-"catch"?](https://stackoverflow.com/questions/2737328/why-should-i-not-wrap-every-block-in-try-catch)
No, it's not "bad practice". It just depends on the situation. 

For example, as an Android, if the user inputs a string "123a" into a text box that is only supposed to accept integers, and is subsequently parsed, an exception will be thrown causing the application to crash. In this case, it would make perfect sense to catch the exception and prompt the user to re-enter the text.