Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7986743
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T11:56:26+00:00 2026-06-04T11:56:26+00:00

I’m writing a library for procedural image generation ( Clisk ) which allows users

  • 0

I’m writing a library for procedural image generation (Clisk) which allows users to define their own mathematical functions to generate images.

It’s clearly possible for them to define a function which could result in a divide by zero for some pixels, e.g. (pseudocode)

red = 1.0 / (xposition - 0.5)

This would result in a divide by zero whenever xposition = 0.5 (the middle of the image)

Ideally I don’t want image generation to crash… but at the same time I don’t want to create a clunky hack to ignore divide by zeros that will cause problems later.

What would be a good, robust, systematic approach to handling these cases?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T11:56:27+00:00Added an answer on June 4, 2026 at 11:56 am

    Ideally I don’t want image generation to crash… but at the same time I don’t want to create a clunky hack to ignore divide by zeros that will cause problems later.

    (I’m assuming you mean the snippet to be an example of some user-supplied code …)

    Clearly, if the user-supplied code could throw exceptions, then you can’t stop that happening. (And the advice to check before division is obviously irrelevant … to you.)

    So what could you do apart from “crash”? Generate an empty image? Ignore the user’s function? You’d be producing garbage … and that’s not what the user needs.

    You certainly can’t reach in and fix his / her java code. (And if that snippet is meant to be code written in some custom language, then you can’t reach in and correct that either. You / your library doesn’t know what the user-supplied code should be doing …)

    No. I reckon that the best answer is to wrap any unexpected (unchecked) exceptions coming out of the user-supplied code in an exception of your own that tells the user clearly that the error occurred in his code. It is then up to the application code calling your library code whether to deal with the exception or “crash”.


    If you are asking for a “good, robust, systematic approach” for users to write their functions, I think you are barking up the wrong tree. And it is not really your concern …

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I would like to run a str_replace or preg_replace which looks for certain words
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from
I am writing an app with both english and french support. The app requests
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.