There’s a fine — nay, invisible — line in comedy between the funny and the offensive, and it is the comedian’s job to find it. The only way to know where it lies without getting tripped up by it is to try to brush up against it, to tickle it with your toe without crossing it. What makes this so hard is the subjectivity of humor. A joke that prompts a belly laugh for one person — or for one audience — can leave others with sour stomachs.

The title character in “The Comedian” is Jackie Burke (Robert De Niro), a washed-up shock comic who is coasting on the success of an old hit sitcom as he struggles to find work in the new landscape of viral comedy. In his stand-up act, Jackie doesn’t so much flirt with that line as deliberately trample it, barging back and forth across it so often as to obliterate it, even as he insults those who would try to maintain the boundary between good and bad taste.

The allure of transgressive humor is, apparently, one of the film’s themes. When Jackie meets a love interest named Harmony Schiltz (Leslie Mann), his natural instincts kick in: “What?” he asks, after learning her name. “Were your parents in a Nazi barbershop quartet?” What passes for a pickup line is actually one of the funnier jokes in the screenplay (by Art Linson, Jeff Ross, Richard LaGravenese and Lewis Friedman), which more often falls flat in its attempt to suss out the sweet spot between what-was-he-thinking and sparkling wit. Whether such awkwardness is intentional or inept is unclear. At times, the barrage of bad jokes seems to invite philosophical contemplation of what’s funny; at others, they just feel like misfires. The fact that the 40-ish Harmony finds Jackie, a foul-mouthed flop nearing 70, not just funny but sexually attractive also makes the film something of a mystery, although it’s far from a thriller. Consider yourself warned.

Jackie Burke (Robert De Niro) meets the much younger Harmony Schiltz (Leslie Mann) while serving community service in “The Comedian,” an encounter that leads to dinner and family misfortune. (Alison Cohen Rosa/Sony Pictures Classics)

The movie by Taylor Hackford (“Ray”) is at heart a shaggy dog story: long, pointless, inconsequential and filled with odd details. Although it hints at the unhappiness — and, occasionally, outright hostility — that underlie humor, “The Comedian” never really seems all that interested in probing the comic’s psychological wounds. Part superficial character sketch and part toothless satire of new media — the film includes Jackie’s brief stint as the host of a “Fear Factor”-style reality television show called “Say Uncle” — “The Comedian” is a baggy clown suit of a film: simultaneously ill-fitting and overly familiar.

Shapeless as it is, the plot is structured around the relationship — if that’s even the right word, and it probably isn’t — between Jackie and Harmony, who meet while doing community service in a New York soup kitchen. He’s working off a criminal sentence for beating up a heckler (Happy Anderson) caught pirating one of Jackie’s live shows for a comedy webcast, and she’s doing time for assaulting a cheating ex and his girlfriend. So much for meeting cute. Between two dates, they manage to squeeze in a one-night stand. The first date is at the lesbian wedding of Jackie’s niece, played by Lucy DeVito (the daughter of Danny DeVito, who plays Jackie’s brother). The second is a dinner with Harmony’s father Mac (Harvey Keitel, who, creepily, is only four years older than De Niro). Both events are disasters, thanks to Jackie’s crass and insult-laden stand-up routine at the wedding reception, which alienates half the people there, and his ungracious refusal to accommodate Mac’s desire for him to recite old sitcom catchphrases.

Patti LuPone as Florence Berkowitz and Danny DeVito as Jimmy Berkowitz in “The Comedian.” (Alison Cohen Rosa/Sony Pictures Classics)

The rest of the narrative concerns Jackie’s attempt to make a comeback, facilitated by his long-suffering manager, played by a deliciously dry Edie Falco. The supporting cast is marvelous, and includes a host of such real-life comics as Billy Crystal, Jimmie Walker, Hannibal Buress and Ryan Hamilton (all playing themselves), along with Patti LuPone, Cloris Leachman and Charles Grodin. And the jazz score and colorful, graffiti and neon-filled New York setting lend “The Comedian,” here and there, the vibe of a poor man’s Woody Allen flick.

Yet at some point the film, like much of Jackie’s humor, goes irredeemably wrong. It’s hard to know exactly where things turns bad; there are so many breaches of decorum and good form along the way, including a stand-up routine, delivered in an old folk’s home, that centers on a scatological parody of the song “Makin’ Whoopee,” and a mawkish attempt to show that Jackie has a heart, when his affair with Harmony takes an unexpected turn.

The real problem, when all is said and done, isn’t the movie but the man with the microphone in its spotlight. Despite two comedy consultants who worked on the film, De Niro’s Jackie never comes across as especially funny on stage (or especially likable off). Rather, as Harmony observes, all too insightfully, about the character’s unfortunate tendency to accumulate ex-wives: “Maybe you’re just an a------.”

R. At area theaters. Contains vulgar language and humor and some violence. 120 minutes.