# Logging system.io.pathtoolongexception

**URL:** <https://forums.powershell.org/t/logging-system-io-pathtoolongexception/17627>\
**Category:** PowerShell Help\
**Created:** [September 24, 2021, 9:50pm UTC](https://forums.powershell.org/t/logging-system-io-pathtoolongexception/17627 "2021-09-24T21:50:46Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![motivatedgorilla](https://avatars.discourse-cdn.com/v4/letter/m/8c91f0/32.png) [@motivatedgorilla](https://forums.powershell.org/u/motivatedgorilla)\
**Post date:** [September 24, 2021, 9:50pm UTC](https://forums.powershell.org/t/logging-system-io-pathtoolongexception/17627/1 "2021-09-24T21:50:46Z")

</div>

I’m new to PowerShell and I’m probably overlooking something obvious. I’m attempting to log `system.io.pathtoolongexception` . The code block does not display a warning (although there are long paths) nor log it to a file.

```auto
catch [system.io.pathtoolongexception] {
            write-warning $("path is too long")
            write-error-log -message $_.exception.message -severity 3
}

```

What am I missing?

---

<div class="post-metadata">

**Author:** ![kvprasoon](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/kvprasoon/32/4449_2.png) [@kvprasoon](https://forums.powershell.org/u/kvprasoon)\
**Post date:** [September 25, 2021, 4:11pm UTC](https://forums.powershell.org/t/logging-system-io-pathtoolongexception/17627/2 "2021-09-25T16:11:37Z")

</div>

@motivatedgorilla Welcome to [PowerShell.org](http://PowerShell.org) forums.

is `write-error-log` your custom function ? Code will enter this catch block only if the exception thrown is `pathtoolongexception`. Try without catch block and see what exception its throwing for long paths.

---

<div class="post-metadata">

**Author:** ![motivatedgorilla](https://avatars.discourse-cdn.com/v4/letter/m/8c91f0/32.png) [@motivatedgorilla](https://forums.powershell.org/u/motivatedgorilla)\
**Post date:** [September 25, 2021, 7:17pm UTC](https://forums.powershell.org/t/logging-system-io-pathtoolongexception/17627/3 "2021-09-25T19:17:27Z")

</div>

@kvprasoon, thanks. No exception is being thrown for long paths although they exist. If I explicitly include a `throw` statement, the `catch` statement returns a message. It however stops the script from running any further i.e. it stops.

---

<div class="post-metadata">

**Author:** ![kvprasoon](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/kvprasoon/32/4449_2.png) [@kvprasoon](https://forums.powershell.org/u/kvprasoon)\
**Post date:** [September 27, 2021, 9:07am UTC](https://forums.powershell.org/t/logging-system-io-pathtoolongexception/17627/4 "2021-09-27T09:07:48Z")

</div>

You could use the `-ErrorAction` parameter for the cmdlet you use with the loing path, `-ErrorAction Stop`. This will make the execution terminate and enter catch block.

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:21pm UTC](https://forums.powershell.org/t/logging-system-io-pathtoolongexception/17627/5 "2024-05-16T20:21:17Z")

</div>


