Responding to Exceptions

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • e_matthes@hotmail.com

    #1

    Responding to Exceptions

    Hello everyone,

    I have set up some custom exceptions, and have managed to implement
    the proper responses to those exceptions. I have something like this:

    try {
    do something;
    } catch (ExceptionA $e) {
    response;
    } catch (ExceptionB $e) {
    response;
    } catch (ExceptionC $e) {
    response;
    } catch (ExceptionD $e) {
    response;
    } catch (Exception $e) {
    respond to unknown exception;
    }

    It's a little clunky though, because sometimes responses to Exceptions
    B, C, and D are the same. Is there any way to collect those specific
    exceptions together in a specific response situation? In other words,
    what I'd love to do is:

    try {
    do something;
    } catch (ExceptionA $e) {
    response;
    } catch (ExceptionB $e OR ExceptionC $e OR ExceptionD $e) {
    response;
    } catch (Exception $e) {
    respond to unknown exception;
    }

    I know I could catch Exception A, then catch the parent Exception
    class, then $e->getcode, and respond to the code in an if-else clause
    or switch clause. But is there any way to do this with the exceptions
    themselves, i.e. catch a group of exceptions together? Thanks.

  • Jerry Stuckle

    #2
    Re: Responding to Exceptions

    e_matthes@hotma il.com wrote:
    Hello everyone,
    >
    I have set up some custom exceptions, and have managed to implement
    the proper responses to those exceptions. I have something like this:
    >
    try {
    do something;
    } catch (ExceptionA $e) {
    response;
    } catch (ExceptionB $e) {
    response;
    } catch (ExceptionC $e) {
    response;
    } catch (ExceptionD $e) {
    response;
    } catch (Exception $e) {
    respond to unknown exception;
    }
    >
    It's a little clunky though, because sometimes responses to Exceptions
    B, C, and D are the same. Is there any way to collect those specific
    exceptions together in a specific response situation? In other words,
    what I'd love to do is:
    >
    try {
    do something;
    } catch (ExceptionA $e) {
    response;
    } catch (ExceptionB $e OR ExceptionC $e OR ExceptionD $e) {
    response;
    } catch (Exception $e) {
    respond to unknown exception;
    }
    >
    I know I could catch Exception A, then catch the parent Exception
    class, then $e->getcode, and respond to the code in an if-else clause
    or switch clause. But is there any way to do this with the exceptions
    themselves, i.e. catch a group of exceptions together? Thanks.
    >
    No, but you can derive B, C and D from the same class (BCD) and handle
    an exception for BCD.

    --
    =============== ===
    Remove the "x" from my email address
    Jerry Stuckle
    JDS Computer Training Corp.
    jstucklex@attgl obal.net
    =============== ===

    Comment

    • e_matthes@hotmail.com

      #3
      Re: Responding to Exceptions

      On Feb 24, 6:03 pm, Jerry Stuckle <jstuck...@attg lobal.netwrote:
      e_matt...@hotma il.com wrote:
      Hello everyone,
      >
      I have set up some custom exceptions, and have managed to implement
      the proper responses to those exceptions. I have something like this:
      >
      try {
      do something;
      } catch (ExceptionA $e) {
      response;
      } catch (ExceptionB $e) {
      response;
      } catch (ExceptionC $e) {
      response;
      } catch (ExceptionD $e) {
      response;
      } catch (Exception $e) {
      respond to unknown exception;
      }
      >
      It's a little clunky though, because sometimes responses to Exceptions
      B, C, and D are the same. Is there any way to collect those specific
      exceptions together in a specific response situation? In other words,
      what I'd love to do is:
      >
      try {
      do something;
      } catch (ExceptionA $e) {
      response;
      } catch (ExceptionB $e OR ExceptionC $e OR ExceptionD $e) {
      response;
      } catch (Exception $e) {
      respond to unknown exception;
      }
      >
      I know I could catch Exception A, then catch the parent Exception
      class, then $e->getcode, and respond to the code in an if-else clause
      or switch clause. But is there any way to do this with the exceptions
      themselves, i.e. catch a group of exceptions together? Thanks.
      >
      No, but you can derive B, C and D from the same class (BCD) and handle
      an exception for BCD.
      >
      --
      =============== ===
      Remove the "x" from my email address
      Jerry Stuckle
      JDS Computer Training Corp.
      jstuck...@attgl obal.net
      =============== ===

      Thank you! That helps.

      Comment

      Working...