• Skip to main content
  • Skip to search
  • Skip to footer
Cadence Home
  • This search text may be transcribed, used, stored, or accessed by our third-party service providers per our Cookie Policy and Privacy Policy.

  1. Community Forums
  2. Custom IC SKILL
  3. 'Throw' and 'Catch' functions

Stats

  • Locked Locked
  • Replies 2
  • Subscribers 143
  • Views 3218
  • Members are here 0
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

'Throw' and 'Catch' functions

MSP032
MSP032 over 6 years ago

HI,

I need some understanding on the 'throw' and 'catch' functions.
I went through their documentation, but I couldn't understand much about them.
Please help me understand the two functions, with some examples on them.

Thanks,
Mallikarjun

  • Cancel
Parents
  • mbracht
    mbracht over 6 years ago

    Hi Mallikarjun,

    throw and catch are a means to define your own exceptions and handle them.
    A throw statement must always occur within a catch block that reflects the name of the throw.
    What happens is that a throw statement makes your code jump to the end of the containing catch
    block rather than returning from the entire function were the exception occured.
    Consider the code below - it's a function that expects a list of positive numeric elements, then
    iterates over that list end performs a division of 1 by that element:

    (defun testIt (ll)
        (catch 'noList
            (unless (listp ll)
                (throw    'noList
                            (warn "%L is not a list\n" ll)))
            (foreach el ll
                (catch t
                    (catch 'zeroElem
                        (when el<0
                            (throw    'zeroElem
                                        (printf "illegal negative element %L\n" el)))
                        (println 1.0/el)
                    )
                )
            )
        )
    )

    In the outer catch block (catch 'noList...) it checkes whether the incoming parameter is a list in
    the first place - if not it throws a 'noList exception, issues a warning statement and jumps to
    the end of the outer catch block. So the first argument to throw() is always the name of the
    exception, the second one a piece of SKILL code to be executed once the exception is thrown.
    In the foreach loop we have two nested catch blocks - the inner one catches negative list elements,
    the outer one catches all potential otherwise fatal exceptions. So neither negative elements nor
    elements being zero (illegal division by zero) stop the foreach loop from going. So (catch t...) is
    a little special because it catches everything (like illegal divisions by zero), not only user defined exceptions.

    Hope that helps a little
    max

    • Cancel
    • Vote Up +1 Vote Down
    • Cancel
  • MSP032
    MSP032 over 6 years ago in reply to mbracht

    Hi Max,

    Thanks a lot.

    The example is very helpful.

    Got an understanding on 'throw' and 'catch' now.

     Mallikarjun  

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
Reply
  • MSP032
    MSP032 over 6 years ago in reply to mbracht

    Hi Max,

    Thanks a lot.

    The example is very helpful.

    Got an understanding on 'throw' and 'catch' now.

     Mallikarjun  

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
Children
No Data

Community Guidelines

The Cadence Design Communities support Cadence users and technologists interacting to exchange ideas, news, technical information, and best practices to solve problems and get the most from Cadence technology. The community is open to everyone, and to provide the most value, we require participants to follow our Community Guidelines that facilitate a quality exchange of ideas and information. By accessing, contributing, using or downloading any materials from the site, you agree to be bound by the full Community Guidelines.

© 2025 Cadence Design Systems, Inc. All Rights Reserved.

  • Terms of Use
  • Privacy
  • Cookie Policy
  • US Trademarks
  • Do Not Sell or Share My Personal Information