<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: in VBA Forum</title>
    <link>https://forums.autodesk.com/t5/vba-forum/raising-errors-in-vba/m-p/315755#M95350</link>
    <description>Thanks Eric,&lt;BR /&gt;
&lt;BR /&gt;
I acutally take things a step further by raising errors in my error handlers&lt;BR /&gt;
so that they can get handled in the calling procedure.  This way I can&lt;BR /&gt;
handle all of my application-specific errors in one routine.  I do something&lt;BR /&gt;
like this:&lt;BR /&gt;
&lt;BR /&gt;
Private Sub ChildProc&lt;BR /&gt;
    On Error GoTo ErrHandler&lt;BR /&gt;
&lt;BR /&gt;
    If &lt;SOME trappable="" error=""&gt; then&lt;BR /&gt;
        Err.Raise ERR_NUMBER,"ChildProc",ERR_DESCRIPTION&lt;BR /&gt;
    End If&lt;BR /&gt;
&lt;BR /&gt;
Exit_ChildProc:&lt;BR /&gt;
    Exit Sub&lt;BR /&gt;
&lt;BR /&gt;
ErrHandler:&lt;BR /&gt;
    With Err&lt;BR /&gt;
        If .Number = ERR_NUMBER Then&lt;BR /&gt;
            .Raise .Number, .Source, .Description&lt;BR /&gt;
        Else&lt;BR /&gt;
            Msgbox Err.Description&lt;BR /&gt;
        End If&lt;BR /&gt;
    Exit With&lt;BR /&gt;
    Resume Exit_ChildProc&lt;BR /&gt;
Exit Sub&lt;BR /&gt;
&lt;BR /&gt;
When error trapping is set to "Break on Unhandled Errors", this works fine.&lt;BR /&gt;
However, every time VBA is initialized, error trapping goes back to the&lt;BR /&gt;
"Break in Class Module" setting.  When in this default setting, errors&lt;BR /&gt;
raised in error handlers get treated like a regular run time error&lt;BR /&gt;
(application crash).&lt;BR /&gt;
&lt;BR /&gt;
If anyone knows how I can set the default error trapping&lt;BR /&gt;
(Options/Tools/General Tab) to "Break on Unhandled Errors", I would greatly&lt;BR /&gt;
appreciate it.  Thanks&lt;BR /&gt;
&lt;BR /&gt;
Jeff&lt;BR /&gt;
&lt;BR /&gt;
eric &lt;ERICK&gt; wrote in message&lt;BR /&gt;
news:8927g5$i216@adesknews2.autodesk.com...&lt;BR /&gt;
&amp;gt; Try something like this&lt;BR /&gt;
&amp;gt;&lt;BR /&gt;
&amp;gt; Sub LayerToggle()&lt;BR /&gt;
&amp;gt;     Dim currLayer As AcadLayer&lt;BR /&gt;
&amp;gt;     Dim newlayer As AcadLayer&lt;BR /&gt;
&amp;gt;     Dim lNameLength As Long&lt;BR /&gt;
&amp;gt;     Dim sName As String&lt;BR /&gt;
&amp;gt;     Dim sRtName As String&lt;BR /&gt;
&amp;gt;&lt;BR /&gt;
&amp;gt;     On Error GoTo Err_LayerToggle&lt;BR /&gt;
&amp;gt;&lt;BR /&gt;
&amp;gt; [notice the above always occurs prior to the real code]&lt;BR /&gt;
&amp;gt; [notice below normally occurs after the real code]&lt;BR /&gt;
&amp;gt;&lt;BR /&gt;
&amp;gt; Exit_LayerToggle:&lt;BR /&gt;
&amp;gt;     ' Clears memory for use by other programs&lt;BR /&gt;
&amp;gt;     Set currLayer = Nothing&lt;BR /&gt;
&amp;gt;     Set newlayer = Nothing&lt;BR /&gt;
&amp;gt;     Exit Sub&lt;BR /&gt;
&amp;gt;&lt;BR /&gt;
&amp;gt; Err_LayerToggle:&lt;BR /&gt;
&amp;gt;     MsgBox Err.Description&lt;BR /&gt;
&amp;gt;     Resume Exit_LayerToggle&lt;BR /&gt;
&amp;gt;&lt;BR /&gt;
&amp;gt; End Sub&lt;BR /&gt;
&amp;gt;&lt;BR /&gt;
&amp;gt; The above is basic error trapping, I do this in every routine I write.&lt;BR /&gt;
&amp;gt;&lt;BR /&gt;
&amp;gt; Good luck,&lt;BR /&gt;
&amp;gt;&lt;BR /&gt;
&amp;gt; Eric&lt;BR /&gt;
&amp;gt;&lt;BR /&gt;
&amp;gt; Jeff Uhlir &lt;JEFFU&gt; wrote in message&lt;BR /&gt;
&amp;gt; news:8920jr$fep61@adesknews2.autodesk.com...&lt;BR /&gt;
&amp;gt; &amp;gt; Is there a way I can set my project's error trapping to break on&lt;BR /&gt;
unhandled&lt;BR /&gt;
&amp;gt; &amp;gt; errors without actually going into the tools/options menu in the editor?&lt;BR /&gt;
&amp;gt; &amp;gt; Since VBA defaults to break in the class module, whenever I try to raise&lt;BR /&gt;
&amp;gt; an&lt;BR /&gt;
&amp;gt; &amp;gt; error, my macro crashes at that point instead of going up the call&lt;BR /&gt;
stack.&lt;BR /&gt;
&amp;gt; &amp;gt; Thanks,&lt;BR /&gt;
&amp;gt; &amp;gt;&lt;BR /&gt;
&amp;gt; &amp;gt; Jeff&lt;BR /&gt;
&amp;gt; &amp;gt;&lt;BR /&gt;
&amp;gt; &amp;gt;&lt;BR /&gt;
&amp;gt;&lt;BR /&gt;
&amp;gt;&lt;/JEFFU&gt;&lt;/ERICK&gt;&lt;/SOME&gt;</description>
    <pubDate>Sun, 14 Dec 2003 04:19:05 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2003-12-14T04:19:05Z</dc:date>
    <item>
      <title>Raising Errors in VBA</title>
      <link>https://forums.autodesk.com/t5/vba-forum/raising-errors-in-vba/m-p/315753#M95348</link>
      <description>Is there a way I can set my project's error trapping to break on unhandled&lt;BR /&gt;
errors without actually going into the tools/options menu in the editor?&lt;BR /&gt;
Since VBA defaults to break in the class module, whenever I try to raise an&lt;BR /&gt;
error, my macro crashes at that point instead of going up the call stack.&lt;BR /&gt;
Thanks,&lt;BR /&gt;
&lt;BR /&gt;
Jeff</description>
      <pubDate>Thu, 24 Feb 2000 01:14:10 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/raising-errors-in-vba/m-p/315753#M95348</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2000-02-24T01:14:10Z</dc:date>
    </item>
    <item>
      <title>Re: Raising Errors in VBA</title>
      <link>https://forums.autodesk.com/t5/vba-forum/raising-errors-in-vba/m-p/315754#M95349</link>
      <description>Try something like this&lt;BR /&gt;
&lt;BR /&gt;
Sub LayerToggle()&lt;BR /&gt;
    Dim currLayer As AcadLayer&lt;BR /&gt;
    Dim newlayer As AcadLayer&lt;BR /&gt;
    Dim lNameLength As Long&lt;BR /&gt;
    Dim sName As String&lt;BR /&gt;
    Dim sRtName As String&lt;BR /&gt;
&lt;BR /&gt;
    On Error GoTo Err_LayerToggle&lt;BR /&gt;
&lt;BR /&gt;
[notice the above always occurs prior to the real code]&lt;BR /&gt;
[notice below normally occurs after the real code]&lt;BR /&gt;
&lt;BR /&gt;
Exit_LayerToggle:&lt;BR /&gt;
    ' Clears memory for use by other programs&lt;BR /&gt;
    Set currLayer = Nothing&lt;BR /&gt;
    Set newlayer = Nothing&lt;BR /&gt;
    Exit Sub&lt;BR /&gt;
&lt;BR /&gt;
Err_LayerToggle:&lt;BR /&gt;
    MsgBox Err.Description&lt;BR /&gt;
    Resume Exit_LayerToggle&lt;BR /&gt;
&lt;BR /&gt;
End Sub&lt;BR /&gt;
&lt;BR /&gt;
The above is basic error trapping, I do this in every routine I write.&lt;BR /&gt;
&lt;BR /&gt;
Good luck,&lt;BR /&gt;
&lt;BR /&gt;
Eric&lt;BR /&gt;
&lt;BR /&gt;
Jeff Uhlir &lt;JEFFU&gt; wrote in message&lt;BR /&gt;
news:8920jr$fep61@adesknews2.autodesk.com...&lt;BR /&gt;
&amp;gt; Is there a way I can set my project's error trapping to break on unhandled&lt;BR /&gt;
&amp;gt; errors without actually going into the tools/options menu in the editor?&lt;BR /&gt;
&amp;gt; Since VBA defaults to break in the class module, whenever I try to raise&lt;BR /&gt;
an&lt;BR /&gt;
&amp;gt; error, my macro crashes at that point instead of going up the call stack.&lt;BR /&gt;
&amp;gt; Thanks,&lt;BR /&gt;
&amp;gt;&lt;BR /&gt;
&amp;gt; Jeff&lt;BR /&gt;
&amp;gt;&lt;BR /&gt;
&amp;gt;&lt;/JEFFU&gt;</description>
      <pubDate>Thu, 24 Feb 2000 03:11:10 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/raising-errors-in-vba/m-p/315754#M95349</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2000-02-24T03:11:10Z</dc:date>
    </item>
    <item>
      <title>Re:</title>
      <link>https://forums.autodesk.com/t5/vba-forum/raising-errors-in-vba/m-p/315755#M95350</link>
      <description>Thanks Eric,&lt;BR /&gt;
&lt;BR /&gt;
I acutally take things a step further by raising errors in my error handlers&lt;BR /&gt;
so that they can get handled in the calling procedure.  This way I can&lt;BR /&gt;
handle all of my application-specific errors in one routine.  I do something&lt;BR /&gt;
like this:&lt;BR /&gt;
&lt;BR /&gt;
Private Sub ChildProc&lt;BR /&gt;
    On Error GoTo ErrHandler&lt;BR /&gt;
&lt;BR /&gt;
    If &lt;SOME trappable="" error=""&gt; then&lt;BR /&gt;
        Err.Raise ERR_NUMBER,"ChildProc",ERR_DESCRIPTION&lt;BR /&gt;
    End If&lt;BR /&gt;
&lt;BR /&gt;
Exit_ChildProc:&lt;BR /&gt;
    Exit Sub&lt;BR /&gt;
&lt;BR /&gt;
ErrHandler:&lt;BR /&gt;
    With Err&lt;BR /&gt;
        If .Number = ERR_NUMBER Then&lt;BR /&gt;
            .Raise .Number, .Source, .Description&lt;BR /&gt;
        Else&lt;BR /&gt;
            Msgbox Err.Description&lt;BR /&gt;
        End If&lt;BR /&gt;
    Exit With&lt;BR /&gt;
    Resume Exit_ChildProc&lt;BR /&gt;
Exit Sub&lt;BR /&gt;
&lt;BR /&gt;
When error trapping is set to "Break on Unhandled Errors", this works fine.&lt;BR /&gt;
However, every time VBA is initialized, error trapping goes back to the&lt;BR /&gt;
"Break in Class Module" setting.  When in this default setting, errors&lt;BR /&gt;
raised in error handlers get treated like a regular run time error&lt;BR /&gt;
(application crash).&lt;BR /&gt;
&lt;BR /&gt;
If anyone knows how I can set the default error trapping&lt;BR /&gt;
(Options/Tools/General Tab) to "Break on Unhandled Errors", I would greatly&lt;BR /&gt;
appreciate it.  Thanks&lt;BR /&gt;
&lt;BR /&gt;
Jeff&lt;BR /&gt;
&lt;BR /&gt;
eric &lt;ERICK&gt; wrote in message&lt;BR /&gt;
news:8927g5$i216@adesknews2.autodesk.com...&lt;BR /&gt;
&amp;gt; Try something like this&lt;BR /&gt;
&amp;gt;&lt;BR /&gt;
&amp;gt; Sub LayerToggle()&lt;BR /&gt;
&amp;gt;     Dim currLayer As AcadLayer&lt;BR /&gt;
&amp;gt;     Dim newlayer As AcadLayer&lt;BR /&gt;
&amp;gt;     Dim lNameLength As Long&lt;BR /&gt;
&amp;gt;     Dim sName As String&lt;BR /&gt;
&amp;gt;     Dim sRtName As String&lt;BR /&gt;
&amp;gt;&lt;BR /&gt;
&amp;gt;     On Error GoTo Err_LayerToggle&lt;BR /&gt;
&amp;gt;&lt;BR /&gt;
&amp;gt; [notice the above always occurs prior to the real code]&lt;BR /&gt;
&amp;gt; [notice below normally occurs after the real code]&lt;BR /&gt;
&amp;gt;&lt;BR /&gt;
&amp;gt; Exit_LayerToggle:&lt;BR /&gt;
&amp;gt;     ' Clears memory for use by other programs&lt;BR /&gt;
&amp;gt;     Set currLayer = Nothing&lt;BR /&gt;
&amp;gt;     Set newlayer = Nothing&lt;BR /&gt;
&amp;gt;     Exit Sub&lt;BR /&gt;
&amp;gt;&lt;BR /&gt;
&amp;gt; Err_LayerToggle:&lt;BR /&gt;
&amp;gt;     MsgBox Err.Description&lt;BR /&gt;
&amp;gt;     Resume Exit_LayerToggle&lt;BR /&gt;
&amp;gt;&lt;BR /&gt;
&amp;gt; End Sub&lt;BR /&gt;
&amp;gt;&lt;BR /&gt;
&amp;gt; The above is basic error trapping, I do this in every routine I write.&lt;BR /&gt;
&amp;gt;&lt;BR /&gt;
&amp;gt; Good luck,&lt;BR /&gt;
&amp;gt;&lt;BR /&gt;
&amp;gt; Eric&lt;BR /&gt;
&amp;gt;&lt;BR /&gt;
&amp;gt; Jeff Uhlir &lt;JEFFU&gt; wrote in message&lt;BR /&gt;
&amp;gt; news:8920jr$fep61@adesknews2.autodesk.com...&lt;BR /&gt;
&amp;gt; &amp;gt; Is there a way I can set my project's error trapping to break on&lt;BR /&gt;
unhandled&lt;BR /&gt;
&amp;gt; &amp;gt; errors without actually going into the tools/options menu in the editor?&lt;BR /&gt;
&amp;gt; &amp;gt; Since VBA defaults to break in the class module, whenever I try to raise&lt;BR /&gt;
&amp;gt; an&lt;BR /&gt;
&amp;gt; &amp;gt; error, my macro crashes at that point instead of going up the call&lt;BR /&gt;
stack.&lt;BR /&gt;
&amp;gt; &amp;gt; Thanks,&lt;BR /&gt;
&amp;gt; &amp;gt;&lt;BR /&gt;
&amp;gt; &amp;gt; Jeff&lt;BR /&gt;
&amp;gt; &amp;gt;&lt;BR /&gt;
&amp;gt; &amp;gt;&lt;BR /&gt;
&amp;gt;&lt;BR /&gt;
&amp;gt;&lt;/JEFFU&gt;&lt;/ERICK&gt;&lt;/SOME&gt;</description>
      <pubDate>Sun, 14 Dec 2003 04:19:05 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/raising-errors-in-vba/m-p/315755#M95350</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2003-12-14T04:19:05Z</dc:date>
    </item>
    <item>
      <title>Re:</title>
      <link>https://forums.autodesk.com/t5/vba-forum/raising-errors-in-vba/m-p/315756#M95351</link>
      <description>Try putting something like&lt;BR /&gt;
    Debug.Assert False&lt;BR /&gt;
&lt;BR /&gt;
just after&lt;BR /&gt;
    Msgbox Err.Description&lt;BR /&gt;
&lt;BR /&gt;
You can force a breakpoint this way that will survive closing the project&lt;BR /&gt;
and all references to Debug are automatically removed when the project is&lt;BR /&gt;
compiled.&lt;BR /&gt;
    --Bill&lt;BR /&gt;
&lt;BR /&gt;
Jeff Uhlir wrote in message &amp;lt;893en5$klf6@adesknews2.autodesk.com&amp;gt;...&lt;BR /&gt;
&amp;gt;Thanks Eric,&lt;BR /&gt;
&amp;gt;&lt;BR /&gt;
&amp;gt;I acutally take things a step further by raising errors in my error&lt;BR /&gt;
handlers&lt;BR /&gt;
&amp;gt;so that they can get handled in the calling procedure.  This way I can&lt;BR /&gt;
&amp;gt;handle all of my application-specific errors in one routine.  I do&lt;BR /&gt;
something&lt;BR /&gt;
&amp;gt;like this:&lt;BR /&gt;
&amp;gt;&lt;BR /&gt;
&amp;gt;Private Sub ChildProc&lt;BR /&gt;
&amp;gt;    On Error GoTo ErrHandler&lt;BR /&gt;
&amp;gt;&lt;BR /&gt;
&amp;gt;    If &lt;SOME trappable="" error=""&gt; then&lt;BR /&gt;
&amp;gt;        Err.Raise ERR_NUMBER,"ChildProc",ERR_DESCRIPTION&lt;BR /&gt;
&amp;gt;    End If&lt;BR /&gt;
&amp;gt;&lt;BR /&gt;
&amp;gt;Exit_ChildProc:&lt;BR /&gt;
&amp;gt;    Exit Sub&lt;BR /&gt;
&amp;gt;&lt;BR /&gt;
&amp;gt;ErrHandler:&lt;BR /&gt;
&amp;gt;    With Err&lt;BR /&gt;
&amp;gt;        If .Number = ERR_NUMBER Then&lt;BR /&gt;
&amp;gt;            .Raise .Number, .Source, .Description&lt;BR /&gt;
&amp;gt;        Else&lt;BR /&gt;
&amp;gt;            Msgbox Err.Description&lt;BR /&gt;
&amp;gt;        End If&lt;BR /&gt;
&amp;gt;    Exit With&lt;BR /&gt;
&amp;gt;    Resume Exit_ChildProc&lt;BR /&gt;
&amp;gt;Exit Sub&lt;BR /&gt;
&amp;gt;&lt;BR /&gt;
&amp;gt;When error trapping is set to "Break on Unhandled Errors", this works fine.&lt;BR /&gt;
&amp;gt;However, every time VBA is initialized, error trapping goes back to the&lt;BR /&gt;
&amp;gt;"Break in Class Module" setting.  When in this default setting, errors&lt;BR /&gt;
&amp;gt;raised in error handlers get treated like a regular run time error&lt;BR /&gt;
&amp;gt;(application crash).&lt;BR /&gt;
&amp;gt;&lt;BR /&gt;
&amp;gt;If anyone knows how I can set the default error trapping&lt;BR /&gt;
&amp;gt;(Options/Tools/General Tab) to "Break on Unhandled Errors", I would greatly&lt;BR /&gt;
&amp;gt;appreciate it.  Thanks&lt;BR /&gt;
&amp;gt;&lt;BR /&gt;
&amp;gt;Jeff&lt;BR /&gt;
&amp;gt;&lt;BR /&gt;
&amp;gt;eric &lt;ERICK&gt; wrote in message&lt;BR /&gt;
&amp;gt;news:8927g5$i216@adesknews2.autodesk.com...&lt;BR /&gt;
&amp;gt;&amp;gt; Try something like this&lt;BR /&gt;
&amp;gt;&amp;gt;&lt;BR /&gt;
&amp;gt;&amp;gt; Sub LayerToggle()&lt;BR /&gt;
&amp;gt;&amp;gt;     Dim currLayer As AcadLayer&lt;BR /&gt;
&amp;gt;&amp;gt;     Dim newlayer As AcadLayer&lt;BR /&gt;
&amp;gt;&amp;gt;     Dim lNameLength As Long&lt;BR /&gt;
&amp;gt;&amp;gt;     Dim sName As String&lt;BR /&gt;
&amp;gt;&amp;gt;     Dim sRtName As String&lt;BR /&gt;
&amp;gt;&amp;gt;&lt;BR /&gt;
&amp;gt;&amp;gt;     On Error GoTo Err_LayerToggle&lt;BR /&gt;
&amp;gt;&amp;gt;&lt;BR /&gt;
&amp;gt;&amp;gt; [notice the above always occurs prior to the real code]&lt;BR /&gt;
&amp;gt;&amp;gt; [notice below normally occurs after the real code]&lt;BR /&gt;
&amp;gt;&amp;gt;&lt;BR /&gt;
&amp;gt;&amp;gt; Exit_LayerToggle:&lt;BR /&gt;
&amp;gt;&amp;gt;     ' Clears memory for use by other programs&lt;BR /&gt;
&amp;gt;&amp;gt;     Set currLayer = Nothing&lt;BR /&gt;
&amp;gt;&amp;gt;     Set newlayer = Nothing&lt;BR /&gt;
&amp;gt;&amp;gt;     Exit Sub&lt;BR /&gt;
&amp;gt;&amp;gt;&lt;BR /&gt;
&amp;gt;&amp;gt; Err_LayerToggle:&lt;BR /&gt;
&amp;gt;&amp;gt;     MsgBox Err.Description&lt;BR /&gt;
&amp;gt;&amp;gt;     Resume Exit_LayerToggle&lt;BR /&gt;
&amp;gt;&amp;gt;&lt;BR /&gt;
&amp;gt;&amp;gt; End Sub&lt;BR /&gt;
&amp;gt;&amp;gt;&lt;BR /&gt;
&amp;gt;&amp;gt; The above is basic error trapping, I do this in every routine I write.&lt;BR /&gt;
&amp;gt;&amp;gt;&lt;BR /&gt;
&amp;gt;&amp;gt; Good luck,&lt;BR /&gt;
&amp;gt;&amp;gt;&lt;BR /&gt;
&amp;gt;&amp;gt; Eric&lt;BR /&gt;
&amp;gt;&amp;gt;&lt;BR /&gt;
&amp;gt;&amp;gt; Jeff Uhlir &lt;JEFFU&gt; wrote in message&lt;BR /&gt;
&amp;gt;&amp;gt; news:8920jr$fep61@adesknews2.autodesk.com...&lt;BR /&gt;
&amp;gt;&amp;gt; &amp;gt; Is there a way I can set my project's error trapping to break on&lt;BR /&gt;
&amp;gt;unhandled&lt;BR /&gt;
&amp;gt;&amp;gt; &amp;gt; errors without actually going into the tools/options menu in the&lt;BR /&gt;
editor?&lt;BR /&gt;
&amp;gt;&amp;gt; &amp;gt; Since VBA defaults to break in the class module, whenever I try to&lt;BR /&gt;
raise&lt;BR /&gt;
&amp;gt;&amp;gt; an&lt;BR /&gt;
&amp;gt;&amp;gt; &amp;gt; error, my macro crashes at that point instead of going up the call&lt;BR /&gt;
&amp;gt;stack.&lt;BR /&gt;
&amp;gt;&amp;gt; &amp;gt; Thanks,&lt;BR /&gt;
&amp;gt;&amp;gt; &amp;gt;&lt;BR /&gt;
&amp;gt;&amp;gt; &amp;gt; Jeff&lt;BR /&gt;
&amp;gt;&amp;gt; &amp;gt;&lt;BR /&gt;
&amp;gt;&amp;gt; &amp;gt;&lt;BR /&gt;
&amp;gt;&amp;gt;&lt;BR /&gt;
&amp;gt;&amp;gt;&lt;BR /&gt;
&amp;gt;&lt;BR /&gt;
&amp;gt;&lt;/JEFFU&gt;&lt;/ERICK&gt;&lt;/SOME&gt;</description>
      <pubDate>Sun, 14 Dec 2003 04:19:05 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/raising-errors-in-vba/m-p/315756#M95351</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2003-12-14T04:19:05Z</dc:date>
    </item>
    <item>
      <title>Re:</title>
      <link>https://forums.autodesk.com/t5/vba-forum/raising-errors-in-vba/m-p/315757#M95352</link>
      <description>There are certain errors that I raise within my validation routine that I&lt;BR /&gt;
handle differently depending on what the calling procedure is.  Becasue of&lt;BR /&gt;
this, I handle these errors in their respective calling procedures.  To do&lt;BR /&gt;
this, I use the Err.Raise method inside my validation routine to send the&lt;BR /&gt;
error back up to the calling proc.  Since this validation routine is inside&lt;BR /&gt;
a class module, it halts execution when it reaches an Err.Raise within an&lt;BR /&gt;
error handler (because error handling is set to "Break in Class Module" by&lt;BR /&gt;
default).  When the error trapping behavior of VB is set to "Break on&lt;BR /&gt;
Unhandled Errors", the error is correctly sent back to the calling routine&lt;BR /&gt;
where it is dealt with properly.&lt;BR /&gt;
&lt;BR /&gt;
Whenever VBA is initialized, the error trapping behavior of VB is set to&lt;BR /&gt;
"Break in Class Module".  I need a way to set the error trapping to "Break&lt;BR /&gt;
on Unhandled Errors" either through code or some other way.  Otherwise, each&lt;BR /&gt;
time VBA is initialized, the VB Editor has to be opened and error trapping&lt;BR /&gt;
manually set.&lt;BR /&gt;
&lt;BR /&gt;
Sorry for the confusion...&lt;BR /&gt;
&lt;BR /&gt;
Jeff&lt;BR /&gt;
&lt;BR /&gt;
Bill Daly &lt;BDALY&gt; wrote in message&lt;BR /&gt;
news:893mts$klf17@adesknews2.autodesk.com...&lt;BR /&gt;
&amp;gt; Try putting something like&lt;BR /&gt;
&amp;gt;     Debug.Assert False&lt;BR /&gt;
&amp;gt;&lt;BR /&gt;
&amp;gt; just after&lt;BR /&gt;
&amp;gt;     Msgbox Err.Description&lt;BR /&gt;
&amp;gt;&lt;BR /&gt;
&amp;gt; You can force a breakpoint this way that will survive closing the project&lt;BR /&gt;
&amp;gt; and all references to Debug are automatically removed when the project is&lt;BR /&gt;
&amp;gt; compiled.&lt;BR /&gt;
&amp;gt;     --Bill&lt;BR /&gt;
&amp;gt;&lt;BR /&gt;
&amp;gt; Jeff Uhlir wrote in message &amp;lt;893en5$klf6@adesknews2.autodesk.com&amp;gt;...&lt;BR /&gt;
&amp;gt; &amp;gt;Thanks Eric,&lt;BR /&gt;
&amp;gt; &amp;gt;&lt;BR /&gt;
&amp;gt; &amp;gt;I acutally take things a step further by raising errors in my error&lt;BR /&gt;
&amp;gt; handlers&lt;BR /&gt;
&amp;gt; &amp;gt;so that they can get handled in the calling procedure.  This way I can&lt;BR /&gt;
&amp;gt; &amp;gt;handle all of my application-specific errors in one routine.  I do&lt;BR /&gt;
&amp;gt; something&lt;BR /&gt;
&amp;gt; &amp;gt;like this:&lt;BR /&gt;
&amp;gt; &amp;gt;&lt;BR /&gt;
&amp;gt; &amp;gt;Private Sub ChildProc&lt;BR /&gt;
&amp;gt; &amp;gt;    On Error GoTo ErrHandler&lt;BR /&gt;
&amp;gt; &amp;gt;&lt;BR /&gt;
&amp;gt; &amp;gt;    If &lt;SOME trappable="" error=""&gt; then&lt;BR /&gt;
&amp;gt; &amp;gt;        Err.Raise ERR_NUMBER,"ChildProc",ERR_DESCRIPTION&lt;BR /&gt;
&amp;gt; &amp;gt;    End If&lt;BR /&gt;
&amp;gt; &amp;gt;&lt;BR /&gt;
&amp;gt; &amp;gt;Exit_ChildProc:&lt;BR /&gt;
&amp;gt; &amp;gt;    Exit Sub&lt;BR /&gt;
&amp;gt; &amp;gt;&lt;BR /&gt;
&amp;gt; &amp;gt;ErrHandler:&lt;BR /&gt;
&amp;gt; &amp;gt;    With Err&lt;BR /&gt;
&amp;gt; &amp;gt;        If .Number = ERR_NUMBER Then&lt;BR /&gt;
&amp;gt; &amp;gt;            .Raise .Number, .Source, .Description&lt;BR /&gt;
&amp;gt; &amp;gt;        Else&lt;BR /&gt;
&amp;gt; &amp;gt;            Msgbox Err.Description&lt;BR /&gt;
&amp;gt; &amp;gt;        End If&lt;BR /&gt;
&amp;gt; &amp;gt;    Exit With&lt;BR /&gt;
&amp;gt; &amp;gt;    Resume Exit_ChildProc&lt;BR /&gt;
&amp;gt; &amp;gt;Exit Sub&lt;BR /&gt;
&amp;gt; &amp;gt;&lt;BR /&gt;
&amp;gt; &amp;gt;When error trapping is set to "Break on Unhandled Errors", this works&lt;BR /&gt;
fine.&lt;BR /&gt;
&amp;gt; &amp;gt;However, every time VBA is initialized, error trapping goes back to the&lt;BR /&gt;
&amp;gt; &amp;gt;"Break in Class Module" setting.  When in this default setting, errors&lt;BR /&gt;
&amp;gt; &amp;gt;raised in error handlers get treated like a regular run time error&lt;BR /&gt;
&amp;gt; &amp;gt;(application crash).&lt;BR /&gt;
&amp;gt; &amp;gt;&lt;BR /&gt;
&amp;gt; &amp;gt;If anyone knows how I can set the default error trapping&lt;BR /&gt;
&amp;gt; &amp;gt;(Options/Tools/General Tab) to "Break on Unhandled Errors", I would&lt;BR /&gt;
greatly&lt;BR /&gt;
&amp;gt; &amp;gt;appreciate it.  Thanks&lt;BR /&gt;
&amp;gt; &amp;gt;&lt;BR /&gt;
&amp;gt; &amp;gt;Jeff&lt;BR /&gt;
&amp;gt; &amp;gt;&lt;BR /&gt;
&amp;gt; &amp;gt;eric &lt;ERICK&gt; wrote in message&lt;BR /&gt;
&amp;gt; &amp;gt;news:8927g5$i216@adesknews2.autodesk.com...&lt;BR /&gt;
&amp;gt; &amp;gt;&amp;gt; Try something like this&lt;BR /&gt;
&amp;gt; &amp;gt;&amp;gt;&lt;BR /&gt;
&amp;gt; &amp;gt;&amp;gt; Sub LayerToggle()&lt;BR /&gt;
&amp;gt; &amp;gt;&amp;gt;     Dim currLayer As AcadLayer&lt;BR /&gt;
&amp;gt; &amp;gt;&amp;gt;     Dim newlayer As AcadLayer&lt;BR /&gt;
&amp;gt; &amp;gt;&amp;gt;     Dim lNameLength As Long&lt;BR /&gt;
&amp;gt; &amp;gt;&amp;gt;     Dim sName As String&lt;BR /&gt;
&amp;gt; &amp;gt;&amp;gt;     Dim sRtName As String&lt;BR /&gt;
&amp;gt; &amp;gt;&amp;gt;&lt;BR /&gt;
&amp;gt; &amp;gt;&amp;gt;     On Error GoTo Err_LayerToggle&lt;BR /&gt;
&amp;gt; &amp;gt;&amp;gt;&lt;BR /&gt;
&amp;gt; &amp;gt;&amp;gt; [notice the above always occurs prior to the real code]&lt;BR /&gt;
&amp;gt; &amp;gt;&amp;gt; [notice below normally occurs after the real code]&lt;BR /&gt;
&amp;gt; &amp;gt;&amp;gt;&lt;BR /&gt;
&amp;gt; &amp;gt;&amp;gt; Exit_LayerToggle:&lt;BR /&gt;
&amp;gt; &amp;gt;&amp;gt;     ' Clears memory for use by other programs&lt;BR /&gt;
&amp;gt; &amp;gt;&amp;gt;     Set currLayer = Nothing&lt;BR /&gt;
&amp;gt; &amp;gt;&amp;gt;     Set newlayer = Nothing&lt;BR /&gt;
&amp;gt; &amp;gt;&amp;gt;     Exit Sub&lt;BR /&gt;
&amp;gt; &amp;gt;&amp;gt;&lt;BR /&gt;
&amp;gt; &amp;gt;&amp;gt; Err_LayerToggle:&lt;BR /&gt;
&amp;gt; &amp;gt;&amp;gt;     MsgBox Err.Description&lt;BR /&gt;
&amp;gt; &amp;gt;&amp;gt;     Resume Exit_LayerToggle&lt;BR /&gt;
&amp;gt; &amp;gt;&amp;gt;&lt;BR /&gt;
&amp;gt; &amp;gt;&amp;gt; End Sub&lt;BR /&gt;
&amp;gt; &amp;gt;&amp;gt;&lt;BR /&gt;
&amp;gt; &amp;gt;&amp;gt; The above is basic error trapping, I do this in every routine I write.&lt;BR /&gt;
&amp;gt; &amp;gt;&amp;gt;&lt;BR /&gt;
&amp;gt; &amp;gt;&amp;gt; Good luck,&lt;BR /&gt;
&amp;gt; &amp;gt;&amp;gt;&lt;BR /&gt;
&amp;gt; &amp;gt;&amp;gt; Eric&lt;BR /&gt;
&amp;gt; &amp;gt;&amp;gt;&lt;BR /&gt;
&amp;gt; &amp;gt;&amp;gt; Jeff Uhlir &lt;JEFFU&gt; wrote in message&lt;BR /&gt;
&amp;gt; &amp;gt;&amp;gt; news:8920jr$fep61@adesknews2.autodesk.com...&lt;BR /&gt;
&amp;gt; &amp;gt;&amp;gt; &amp;gt; Is there a way I can set my project's error trapping to break on&lt;BR /&gt;
&amp;gt; &amp;gt;unhandled&lt;BR /&gt;
&amp;gt; &amp;gt;&amp;gt; &amp;gt; errors without actually going into the tools/options menu in the&lt;BR /&gt;
&amp;gt; editor?&lt;BR /&gt;
&amp;gt; &amp;gt;&amp;gt; &amp;gt; Since VBA defaults to break in the class module, whenever I try to&lt;BR /&gt;
&amp;gt; raise&lt;BR /&gt;
&amp;gt; &amp;gt;&amp;gt; an&lt;BR /&gt;
&amp;gt; &amp;gt;&amp;gt; &amp;gt; error, my macro crashes at that point instead of going up the call&lt;BR /&gt;
&amp;gt; &amp;gt;stack.&lt;BR /&gt;
&amp;gt; &amp;gt;&amp;gt; &amp;gt; Thanks,&lt;BR /&gt;
&amp;gt; &amp;gt;&amp;gt; &amp;gt;&lt;BR /&gt;
&amp;gt; &amp;gt;&amp;gt; &amp;gt; Jeff&lt;BR /&gt;
&amp;gt; &amp;gt;&amp;gt; &amp;gt;&lt;BR /&gt;
&amp;gt; &amp;gt;&amp;gt; &amp;gt;&lt;BR /&gt;
&amp;gt; &amp;gt;&amp;gt;&lt;BR /&gt;
&amp;gt; &amp;gt;&amp;gt;&lt;BR /&gt;
&amp;gt; &amp;gt;&lt;BR /&gt;
&amp;gt; &amp;gt;&lt;BR /&gt;
&amp;gt;&lt;BR /&gt;
&amp;gt;&lt;/JEFFU&gt;&lt;/ERICK&gt;&lt;/SOME&gt;&lt;/BDALY&gt;</description>
      <pubDate>Sun, 14 Dec 2003 04:19:05 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/raising-errors-in-vba/m-p/315757#M95352</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2003-12-14T04:19:05Z</dc:date>
    </item>
  </channel>
</rss>

