1

I'm using the UrbanAirship library and importing it into my php script and then using it like so:

use UrbanAirship\Push as P;

// Down inside some method...
try {
    $dev = P\deviceToken('....');
} catch (InvalidArgumentException $e) {
    continue;
}

If I look at the deviceToken method I see them throwing the InvalidArgumentException on bad input. However, when this happens, my script just aborts with the exception, instead of catching it and moving on.

Is there something special I have to do to catch this exception?

1
  • What exception does it throw ?
    – Rizier123
    Commented May 7, 2015 at 22:23

2 Answers 2

2

I have a feeling that namespaces might be complicating your issue.

When catching an exception inside a namespace it is important that you escape to the global space.

Try this:

use UrbanAirship\Push as P;

// Down inside some method...
try {
    $dev = P\deviceToken('....');
} catch (\InvalidArgumentException $e) {
    continue;
}
1
  • 1
    Thank you, that was the issue! Adding the \ in front of the exception name made it work as expected.
    – Gargoyle
    Commented May 8, 2015 at 15:48
0
continue;

only works in loops. If you don't want to do anything with the exception, simply leave the catch block empty.

use UrbanAirship\Push as P;

// Down inside some method...
try {
    $dev = P\deviceToken('....');
} catch (InvalidArgumentException $e) {
    // Do nothing
}
1
  • I am in a loop. I was just showing a snipped. Even if that weren't the case though, your suggestion didn't address the issue that the exception was not being caught.
    – Gargoyle
    Commented May 8, 2015 at 16:00

Not the answer you're looking for? Browse other questions tagged or ask your own question.