Latest Uploads
Super Shap ... ration Kit

Andy_A

Platdude Spotting

Jayenkai

Nom nom nom

Jayenkai

Rainbow Trout

Pakz

King Salmon

Pakz

Snooker

Jayenkai

Code Snippets > Misc ( Created 01 December 2012 | Last Edited 01 December 2012)

Better C error handling with goto and macros by HoboBen | No Votes
Written in
Monkey
I use gotos for error handling in C. (yes this is a valid use for gotos). It allows me to jump to any point in cleanup section.

For a good example, see StackOverflow: stackoverflow.com/questions/788903/valid-use-of-goto-for-error-management-in-c

It just occurred to me that I could throw in a macro and automatically get pretty error messages for every error handled, no extra work.

It gives me nice output like:

ced: ../src/canvas.c:183 OpenCanvas: Exception 'err_already_open' at line 183


Here's an example that checks for valid arguments, allocates some memory, and at any point can unwind from an error.

-->

Just include this somewhere:

-->

There are no comments for this entry. -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- (c) WidthPadding Industries 1987 732|0 -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=-
Latest Posts
Steve's Car Buying Disaster
steve_ancell Wed 14:32
New Pound Coin
Jayenkai Tue 14:45
Homefries
steve_ancell Tue 01:47
Jeremy Bloody Kyle
steve_ancell Mon 09:45
GamerBlock
Jayenkai Mon 09:06
Laptop Aaargh...
Jayenkai Mon 07:06
Changing Thumbnail Sizes
Jayenkai Mon 05:27
Technology on Planes
therevillsgames Sat 17:00
London Car/Stab Incident
steve_ancell Sat 12:10
A New Korg Gadget!
Jayenkai Sat 04:53
More

Latest Items
Dev-Diary : Sensitive - Arduboy!
Jayenkai Thu 05:03
Link : Super Shapes Exploration Kit
Andy_A Tue 16:56
Snippet : Skylines
steve_ancell Tue 14:25
Blog : My Arduino experience.
steve_ancell Fri 13:45
Showcase : Infinitron
rychan Tue 03:02
Dev-Diary : PS2 to N64 Adapter
spinal Sun 10:49
Link : Vector Tutorials/Help page.
Pakz Thu 23:00
Blog : mini project
spinal Sun 10:13
Showcase : Blockman Returns
Jayenkai Fri 03:04
Snippet : Wall Tracing on Random Maps (rpg)
rskgames Wed 22:48
Snippet : Path Following
Pakz Mon 16:25
Snippet : Flowers (Jan 2017)
Kuron Thu 01:13
Showcase : Clusters of Hex
therevillsgames Mon 15:01
Article : Maths 101 - Episode 1: Basic Trigonometry
shroom_monk Sun 14:07
Article : Maths 101 - Episode 5: Line Intersection
shroom_monk Sun 14:02
More

Who's Online
Pakz
Thu, at 12:33
Jayenkai
Thu, at 12:32
spinal
Thu, at 12:20
Andy_A
Thu, at 09:58
rychan
Thu, at 09:56
rockford
Thu, at 07:45
steve_ancell
Thu, at 03:36
rskgames
Thu, at 03:09
Evil Roy Ferguson
Wed, at 19:54
9572AD
Wed, at 17:27
Link to this page
Site : Jayenkai 2006-Infinity | MudChat's origins, BBCode's former life, Image Scaler.