※当サイトの記事には、広告・プロモーションが含まれます。

awkでError Handling(Exception Handling)はできないっぽい、たぶん

www.itmedia.co.jp

 Grok-1は、Kubernetes、Rust、JAXに基づくカスタムトレーニングおよび推論スタックを使用してトレーニングされている。Grokはインターネットにアクセスして最新情報にリアルタイムでアクセスできるため、「誤った情報や矛盾した情報が生成される可能性がある」とxAIは説明する。

xAI、“全人類に利益をもたらすAIツール”を目指す「Grok」正式発表 - ITmedia NEWS

将来のモデルはそうした問題を軽減するために、以下の領域の研究を進めるとしている。

  • AIの支援を利用した人間によるスケーラブルなモデルの監視
  • 推論と安全性の向上のための正式な検証
  • 長い文脈の理解と検索
  • 敵対的な堅牢性
  • 視覚や音声などのマルチモーダルスキル

xAI、“全人類に利益をもたらすAIツール”を目指す「Grok」正式発表 - ITmedia NEWS

⇧ リアルタイムな情報に追随しつつ、情報の整合性と確からしさを維持するように性能をアップデートしていくのが大変そうね。

awkでError Handling(Exception Handling)はできないっぽい、たぶん

ネットの情報だと、

In computing and computer programmingexception handling is the process of responding to the occurrence of exceptions – anomalous or exceptional conditions requiring special processing – during the execution of a program. In general, an exception breaks the normal flow of execution and executes a pre-registered exception handler; the details of how this is done depend on whether it is a hardware or software exception and how the software exception is implemented.

https://en.wikipedia.org/wiki/Exception_handling

History

The first hardware exception handling was found in the UNIVAC I from 1951.

https://en.wikipedia.org/wiki/Exception_handling

⇧「ハードウェア」の分野だと、1951年頃から「Error Handling(Exception Handling)」の仕組みが導入されていたらしい。

ソフトウェアの分野だと、

In computer programming, several language mechanisms exist for exception handling. The term exception is typically used to denote a data structure storing information about an exceptional condition. One mechanism to transfer control, or raise an exception, is known as a throw; the exception is said to be thrown. Execution is transferred to a catch.

https://en.wikipedia.org/wiki/Exception_handling_(programming)

History

Software exception handling developed in the 1960s and 1970s. LISP 1.5 (1958-1961) allowed exceptions to be raised by the ERROR pseudo-function, similarly to errors raised by the interpreter or compiler. Exceptions were caught by the ERRORSET keyword, which returned NIL in case of an error, instead of terminating the program or entering the debugger.

https://en.wikipedia.org/wiki/Exception_handling_(programming)

⇧ 1960年代に「Error Handling(Exception Handling)」の仕組みが導入されていたそうな。

C does not provide direct support for error handling (also known as exception handling).

https://en.wikibooks.org/wiki/C_Programming/Error_handling

⇧「exception handling」と呼ぶのが一般的っぽいみたいですかね。

Wikipediaさんによると、

Syntax

Many computer languages have built-in syntactic support for exceptions and exception handling. This includes ActionScriptAdaBlitzMaxC++C#ClojureCOBOLDECMAScriptEiffelJavaMLObject Pascal (e.g. DelphiFree Pascal, and the like), PowerBuilderObjective-COCamlPHP (as of version 5), PL/IPL/SQLPrologPythonREALbasicRubyScalaSeed7SmalltalkTclVisual Prolog and most .NET languages.

https://en.wikipedia.org/wiki/Exception_handling_(programming)

⇧ 昨今のメジャーなプログラミング言語であれば、「exception handling」の仕組みは導入されてるっぽい。

で、お察しの通り、

  • ShellScript
  • AWK

については、そもそも「exception handling」について触れられていない...

ネットの情報だと、

xmadoka.hatenablog.com

⇧「ShellScript」については、「trap」というコマンドの機能によって、「exception handling」のようなことが実現できる模様。

で、残念ながら、「AWK」では、「exception handling」的なことを実現するのは難しいようで、

unix.stackexchange.com

⇧ 上記サイト様によりますと、「ShellScript」側の「$?(特殊変数)」で判断するしかないっぽい。

ただ、「AWK」側でエラーが起こっていたとしても、「ShellScript」側へエラーに該当する「$?(特殊変数)」の値が連携されるのかが分からない...

GNU」の「AWK」のドキュメントによると、

www.gnu.org

In traditional implementations of awk, the only way to write an error message to standard error in an awk program is as follows:

print "Serious error detected!" | "cat 1>&2"

https://www.gnu.org/software/gawk/manual/gawk.html#index-error-handling

⇧ 索引の「error handling」のリンクで遷移した行の説明を見ても、エラーを捕捉する仕組みは用意されていないっぽいように見える...

他には、

Normally, when an error occurs when reading input in the normal input-processing loop, the error is fatal. However, if a BEGINFILE rule is present, the error becomes non-fatal, and instead ERRNO is set. This makes it possible to catch and process I/O errors at the level of the awk program.

https://www.gnu.org/software/gawk/manual/gawk.html

⇧ 入力処理のエラーは、「ERRNO」を確認すれば分かるようにはなっているらしい。

こちらについては、

linuxcommand.net

⇧ 上記サイト様が詳しいです。

AWK」のエラーの種類の全量が分からんので何とも言えんのだけど、基本的に、エラーが発生しているかどうかを捕捉できるような「Error Handling(Exception Handling)」の仕組みは無さそうではありますと。

「ShellScript」側の「$?(特殊変数)」で判断できるように、「AWK」側で条件分岐とかを駆使して、期待した処理ができていなければ「0」以外の値を無理やり返す感じで対応するしかないんかな?

ちなみに、「Error Handling(Exception Handling)」と関係ないけど、

b.ueda.tech

⇧ 出力する時にも、データ型を気にした方が良いっぽいですな。

結局のところ、「AWK」で「Error Handling(Exception Handling)」っぽいことを実現するベストプラクティスってのが分かりませんでした...

毎度モヤモヤ感が半端ない...

今回はこのへんで。