in reply to Enforcing exception catching

Is there a way to force calling functions to place calls to things that can throw exceptions in try{} block?
Well, almost anything is possible in Perl. You could, after compilation, put all functions in wrappers where the wrapper walks the call stack and searches for a try. If only some functions throw exceptions, you can give those functions an attribute, and use the attribute mechanism to place those functions in wrappers.

This is of course costly, as any function call is replaced with two calls, with doing some work in between as well. You can of course use a switch (command-line argument, environment variable, etc) that recognizes a development or testing environment, and only places wrappers in development and testing environments. This requires your test set to cover all function calls (this is different from having all functions called!).

Abigail

Replies are listed 'Best First'.
Re: Re: Enforcing exception catching
by dmitri (Priest) on Feb 12, 2004 at 16:08 UTC
    That's a good idea. The problem is that we have a lot of functions that throw exceptions, and I guess the best way to place them in wrappers is to use attributes with Attribute::Handlers. I don't know if I want to edit dozens of libraries to add attributes to functions, but I just may have to.

    The test suite also needs improvement.