Board index » Visual Studio » Error/Exception Handling Question?

Error/Exception Handling Question?

Visual Studio300
List:



I'm trying to get my app to play nice with multiple printers.



I'm using the PrinterDlg form from Microsoft.



One of the printers here objects strongly to having its properties set,

whereas the other happily complies with even nonsensical things I ask it

to do.



So when I choose the laserjet, I get an error:



NewPrinter.PaperSize = printDlg.PaperSize



(and similar statements)



That the property is "ReadOnly."



My first instinct is when I enter the block of statements that sets the

printer properties to us "On Error Resume Next"



My concern is that this function might be called from most anywhere, and

I don't want to undo the error handling of the calling context.



If I do:



On Error Resume Next



' Set various printer properties



On Error Goto 0



Does that restore the error trapping of the calling context, or do I

need to do something more complex in this situation?



Thanx





Charles


-
 

Re:Error/Exception Handling Question?

Charles,

Put the printer functions in a separate function (sub). Use error trapping

there and either pass back an error code or handle the error in the function

(or sub). This way, the error handling properties of the calling app will

not be affected.

HTH,

CF

"U-CDK_CHARLES\Charles" <"Charles Krug"@aol.com>wrote in message

Quote
List:



I'm trying to get my app to play nice with multiple printers.



I'm using the PrinterDlg form from Microsoft.



One of the printers here objects strongly to having its properties set,

whereas the other happily complies with even nonsensical things I ask it

to do.



So when I choose the laserjet, I get an error:



NewPrinter.PaperSize = printDlg.PaperSize



(and similar statements)



That the property is "ReadOnly."



My first instinct is when I enter the block of statements that sets the

printer properties to us "On Error Resume Next"



My concern is that this function might be called from most anywhere, and

I don't want to undo the error handling of the calling context.



If I do:



On Error Resume Next



' Set various printer properties



On Error Goto 0



Does that restore the error trapping of the calling context, or do I

need to do something more complex in this situation?



Thanx





Charles









-

Re:Error/Exception Handling Question?

On Error statements only apply to the current Sub/Function. An On Error

statement will not change any On Error's that have been set up in

other/calling routines. If your code is in a separate Function/Sub, you

don't need to worry about anything. Do whatever On Error you like.



-Tom



"U-CDK_CHARLES\Charles" <"Charles Krug"@aol.com>wrote in message

Quote
List:



I'm trying to get my app to play nice with multiple printers.



I'm using the PrinterDlg form from Microsoft.



One of the printers here objects strongly to having its properties set,

whereas the other happily complies with even nonsensical things I ask it

to do.



So when I choose the laserjet, I get an error:



NewPrinter.PaperSize = printDlg.PaperSize



(and similar statements)



That the property is "ReadOnly."



My first instinct is when I enter the block of statements that sets the

printer properties to us "On Error Resume Next"



My concern is that this function might be called from most anywhere, and

I don't want to undo the error handling of the calling context.



If I do:



On Error Resume Next



' Set various printer properties



On Error Goto 0



Does that restore the error trapping of the calling context, or do I

need to do something more complex in this situation?



Thanx





Charles









-