Windows Vista Forums

Confusing exception trapping behaviour
  1. #1


    david.jade Guest

    Confusing exception trapping behaviour

    I've got a small example of exception trapping that doesn't seem to be
    working right, or at least how I would expect it to work:

    Trap
    {
    'caught general exception: ' + $_.Exception.Message
    }


    function Test
    {
    trap [System.ComponentModel.Win32Exception]
    {
    'caught Win32 exception'

    # re-throw exception
    throw $_
    }

    # throw a non-win32 exception
    throw 'string-exception'
    }



    When you invoke the Test function, none of the trap handlers get invoked.
    Shouldn't the general trap handler get invoked in this case? It seems to be
    the type-specific trap handler within the function that is causing the outer
    trap handler to get ignored. If you remove the type from the function's
    exception trap, then the outer exception trap will then work.

    Is this right? Shouldn't I be able to catch a specific exception type and
    allow all others to propogate to other handlers?

    thanks,
    david



      My System SpecsSystem Spec

  2. #2


    klumsy@xtra.co.nz Guest

    Re: Confusing exception trapping behaviour

    Try this

    Trap [system.Exception]
    {
    'caught general exception: ' + $_.Exception.Message



    }


    function Test
    {
    trap [System.ComponentModel.Win32Exception]
    {
    'caught Win32 exception'

    # re-throw exception
    throw $_
    }


    # throw a non-win32 exception
    throw 'string-exception'



    }


      My System SpecsSystem Spec

  3. #3


    david.jade Guest

    Re: Confusing exception trapping behaviour

    I've tried that. As long as the exception type exists on the function's trap
    handler the outer scope trap handler never gets invoked.

    "klumsy@xtra.co.nz" wrote:

    > Try this
    >
    > Trap [system.Exception]
    > {
    >


      My System SpecsSystem Spec

Confusing exception trapping behaviour problems?

Similar Threads
Thread Thread Starter Forum Replies Last Post
Exception stack is corrupt when catching and storing the exception Morten Herman Langkjaer .NET General 1 05 Mar 2008
Vista Install Error: Exception Unknown Software Exception burntham77 Vista installation & setup 2 07 Jan 2008
Confusing shortcut behaviour when merging with folder of same name pd5rm Vista General 0 28 Oct 2007
Question on Exception Trapping Brandon Shell PowerShell 6 07 Sep 2007
Trapping exceptions =?Utf-8?B?UmF5IEhheWVz?= PowerShell 3 11 Sep 2006