help-gawk
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to make "division by zero attempted" error message more informat


From: Neil R. Ormos
Subject: Re: How to make "division by zero attempted" error message more informative?
Date: Thu, 3 Mar 2022 12:16:54 -0600 (CST)

Peng Yu wrote:

> I see something like this. But when this kind of command is called at
> multiple scripts. It is hard to tell where the error is from.
>
> $ awk -e '{ print 10/$1 }' <<< 0
> awk: cmd. line:1: (FILENAME=- FNR=1) fatal: division by zero attempted
>
> Is there a way to customize the error message so that I can know where the
> error is coming from? Thanks.

One way to address this:

Gawk error messages are prefaced with the name by which gawk was called.

For each call to gawk in the multiple scripts, you could create a symlink to 
the gawk executable with a different distinguishing name, and then call gawk 
using that name.  Then, each error message will be prefaced by the 
distinguishing name.

E.g., if you had something like this in the calling scripts (having already 
made the appropriate symlinks):

   ...
   gawk-special55     '{print    $1/0}'
   ...
   gawk-special66     '{print    $1/0}'
   ...
   gawk-special77     '{print    $1/0}'
   ...

the error message would finger the particular calling instance, like so:

  gawk-special55: cmd. line:1: (FILENAME=- FNR=1) fatal: division by zero 
attempted
  ==============



reply via email to

[Prev in Thread] Current Thread [Next in Thread]